centos 编译opencv_4.2.0(dnn可以使用gpu)
git clone https://github.com/opencv/opencv.git
cd opencv-4.2.0/ mkdir build cd build/ cmake -D CMAKE_BUILD_TYPE=RELEASE -D OPENCV_GENERATE_PKGCONFIG=ON -D CMAKE_INSTALL_PREFIX=/usr/local .. make -j8 sudo make install
以上编译的是cpu版本
下面开始编译gpu版本
网上有很多。神马opencv与opencv_contrib版本不匹配等。不匹配的话cmake会直接报错。改了N次也不见好。后来干看错误直接改代码得了
报错位置:
//#include "opencv2/xfeatures2d/nonfree.hpp"
修改为:(自己按自己目录来)
# include "D:\\opencv_contrib-master\\modules\xfeatures2d\include\opencv2\xfeatures2d\nonfree.hpp" (换成自己的路径)
INCLUDE_DIRECTORIES("/home/opencv_ext/opencv_contrib/modules/xfeatures2d/include")
cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/home/cudnn_opencv_gpu -DWITH_TBB=ON -DWITH_V4L=ON -DWITH_OPENGL=ON -DWITH_CUDA=ON -DWITH_CUDNN=ON -D CUDA_ARCH_BIN=5.3,6.0,6.1,7.0,7.5 -DCUDA_ARCH_PTX=7.5 -DENABLE_FAST_MATH=1 -DCUDA_FAST_MATH=1 -DCUDA_NVCC_FLAGS="-D_FORCE_INLINES" -DWITH_CUBLAS=1 -DOPENCV_EXTRA_MODULES_PATH=/home/opencv_ext2/opencv_contrib/modules ..
INCLUDE_DIRECTORIES("/home/opencv_ext/opencv_contrib/modules/xfeatures2d/include")
编译命令(需要先安装好cuda ,cudnn,cudnn-devel等库,库文件太大,可与我联系索要)
cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/home/cudnn_opencv -DWITH_TBB=ON -DWITH_V4L=ON -DWITH_OPENGL=ON -DWITH_CUDA=ON -DWITH_CUDNN=ON -D OPENCV_DNN_CUDA=ON -D CUDA_ARCH_BIN=6.0,6.1,7.0,7.5 -DCUDA_ARCH_PTX=7.5 -DENABLE_FAST_MATH=1 -DCUDA_FAST_MATH=1 -DCUDA_NVCC_FLAGS="-D_FORCE_INLINES" -DWITH_CUBLAS=1 -DOPENCV_EXTRA_MODULES_PATH=/home/opencv_ext2/opencv_contrib/modules ..
部分.i下载失败需要手动下载
缺少文件的需要到opencv源码目录下找,复制到需要的位置,修改头文件中的路径
找不到libtbb.so.2
执行
yum install libtbb*
使用opencv gpu
g++ /root/test_model.cpp -I/root/opencv_lib_gpu/include/opencv4/ -L/root/opencv_lib_gpu/lib64 -lopencv_highgui -lopencv_imgcodecs -lopencv_core -lopencv_video -lopencv_imgproc -lopencv_imgcodecs -lopencv_objdetect -lopencv_ml -lopencv_calib3d -lopencv_dnn -lopencv_features2d -lopencv_flann -lopencv_videoio -lopencv_photo -lopencv_cudev -lopencv_cudaimgproc -lopencv_cudaarithm -lm -ldl -lpthread -lrt -lssl -lcrypt -lcrypto -lz -lstdc++ -std=c++11 -o test_model
https://blog.csdn.net/lzhkui/article/details/107157175 nppi库错误,更新cmake 3.17后正常