Install
-
mkdir build && cd build
-
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D FORCE_VTK=ON -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D WITH_CUBLAS=ON -D OPENCV_GENERATE_PKGCONFIG=ON -D CUDA_NVCC_FLAGS="-D_FORCE_INLINES --expt-relaxed-constexpr" -D WITH_GDAL=ON -D WITH_XINE=ON -D BUILD_EXAMPLES=ON -D OPENCV_EXTRA_MODULES_PATH=/home/software/opencv_contrib-4.0.0/modules -D PYTHON3_EXECUTABLE=/home/software/miniconda3/envs/tnn/bin/python -D PYTHON3_NUMPY_INCLUDE_DIRS=/home/software/miniconda3/envs/tnn/lib/python3.6/site-packages/numpy/core/include -D PYTHON3_PACKAGES_PATH=/home/software/miniconda3/envs/tnn/lib/python3.6/site-packages ..
- CUDA_NVCC_FLAGS is for cuda9.0 according to Ubuntu 16.04 or 15.10 Installation Guide.
- PYTHON3_EXECUTABLE, PYTHON3_NUMPY_INCLUDE_DIRS, PYTHON3_PACKAGES_PATH is used to bind opencv with conda environment.
- OPENCV_EXTRA_MODULES_PATH is used to install opencv contrib
make -j $(($(nproc) + 1))
sudo make install
sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig
sudo apt update
python binding for opencv (optionally)
-
cd /home/software/miniconda3/envs/tnn/lib/python3.6/site-packages
-
ln -s /usr/local/python/cv2/python-3.6/cv2.cpython-36m-x86_64-linux-gnu.so cv2.cpython-36m-x86_64-linux-gnu.so
-
reboot
In [1]: import cv2
In [2]: cv2.__version__
Out[2]: '4.0.0'
work with CMake
// DisplayImage.cpp
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char **argv) {
if (argc != 2) {
cout << " Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread(argv[1], IMREAD_COLOR); // Read the file
if (!image.data) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl;
return -1;
}
namedWindow("Display window", WINDOW_AUTOSIZE);// Create a window for display.
imshow("Display window", image); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0;
}
# CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(DisplayImage)
set(CMAKE_CXX_STANDARD 11)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
message(${OpenCV_INCLUDE_DIRS})
add_executable(DisplayImage DisplayImage.cpp)
target_link_libraries(DisplayImage ${OpenCV_LIBS})
message(${OpenCV_LIBS})