Ubuntu16.04下Opencv3.4.5的卸载与带cuda安装

一、opencv卸载

参考链接:
https://blog.csdn.net/weixin_45617478/article/details/102632088

二、opencv3.4.5安装

(一)cmake安装参考语句

mkdir build
 cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-3.4.5/modules/ -D CUDA_CUDA_LIBRARY=/usr/local/cuda/lib64/stubs/libcuda.so -D CUDA_ARCH_BIN=6.1 -D CUDA_ARCH_PTX=""   -D WITH_CUDA=ON -D WITH_TBB=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1 -D WITH_CUBLAS=1 -D WITH_NVCUVID=1 -D BUILD_opencv_cudacodec=OFF ..
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local …
cmake -D CMAKE_BUILD_TYPE=RELEASE   -D CMAKE_INSTALL_PREFIX=/usr/local   -D WITH_TBB=ON -D WITH_V4L=ON   -D WITH_QT=ON   -D WITH_OPENGL=ON   -D WITH_CUDA=ON   -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1   -D CUDA_NVCC_FLAGS="-D_FORCE_INLINES"   -D WITH_CUBLAS=1 -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-3.4.5/modules/ -D CUDA_GENERATION=Kepler -D OPENCV_ENABLE_NONFREE=True ..

打开终端,输入

gedit ~/DownLoad/opencv_source/opencv/3rdparty/ippicv/ippicv.cmake
“https://raw.githubusercontent.com/opencv/opencv_3rdparty/${IPPICV_COMMIT}ippicv/”

改为中手动下载的文件的本地路径(也就是将网络下载的模式改为本地文件下载的模式):
“file:~/Downloads/” #(仅供参考,根据自己的路径填写)

(二)问题处理

1、fatal error: dynlink_nvcuvid.h: No such file or directory

参考连接:https://blog.csdn.net/y459541195/article/details/102974262

cmake 时添加-D BUILD_opencv_cudacodec=OFF
如果不想注释,也可以参考下面博客
https://www.cnblogs.com/penguins/p/10214817.html
即可通过。

2、opencv_annotation.dir/build.make recipe for target ‘bin/opencv_annotation’ failed

参考链接:https://blog.csdn.net/splend520/article/details/97270438
问题提示与anaconda有关:/home/xxx/anaconda3/lib/libtiff.so.5: undefined reference to `ZSTD_initCStream’

解决如下:
在终端下修改$PATH的值,删除build,重新编译。

3、CMake Error at cmake/OpenCVModule.cmake:288 (message): No modules has been found:

git clone https://github.com/opencv/opencv_contrib.git

然后,就有opencv_contrib 的path

如果版本不对

cd opencv_contrib
git checkout 3.1.0   别忘了check你的版本

4、boostdesc_bgm.i等文件下载

在安装含opencv_contrib的opencv时,会需要下载boostdesc_bgm.i等文件的情况,可参考下面博客,下载、添加:
https://blog.csdn.net/wq1psa78/article/details/105334859
但是,我在按照上述博客操作完后,依然会显示下载(虽然下载不了不影响编译,但会显示正在下载一段时间),因此可opencv-3.4.5/opencv_contrib-3.4.5/modules/xfeatures2d/cmake目录下对download_boostdesc.cmake、download_vgg.cmake文件的下载函数进行注释,效果如下图:
Ubuntu16.04下Opencv3.4.5的卸载与带cuda安装_第1张图片
Ubuntu16.04下Opencv3.4.5的卸载与带cuda安装_第2张图片

5、fatal error: unsupported/Eigen/MatrixFunctions: No such file or directory

参考如下链接:
https://www.freesion.com/article/7083607851/

6、error: ‘integer_sequence’ is not a member of ‘std‘

参考如下链接:
https://blog.csdn.net/qq_41586768/article/details/107541917
不过我失败了,因为我已经安装了Eigen3.3.9,与ceres-solver-1.14.0不匹配,不想换了,可直接改C++版本,参考如下链接:
https://blog.csdn.net/AUV_SLAM/article/details/121892017

7、simple_pipeline.cpp:44:35: fatal error: opencv2/xfeatures2d.hpp: No such file or directory

参考链接:
https://its401.com/article/z952957407/103116783
在opencv-3.4.5/opencv_contrib-3.4.5/modules/sfm文件夹下修改CMakeLists.txt:
Ubuntu16.04下Opencv3.4.5的卸载与带cuda安装_第3张图片
然而,有一个文件我始终改了之后没有反应,报错:matchers.hpp:52:42: fatal error: opencv2/xfeatures2d/cuda.hpp: No such file or directory
因此,我索性将cuda.cpp直接拷贝到matchers.hpp同目录下,并修改CMakeList.txt如下,编译通过
Ubuntu16.04下Opencv3.4.5的卸载与带cuda安装_第4张图片
大功告成!
Ubuntu16.04下Opencv3.4.5的卸载与带cuda安装_第5张图片

三、opencv4.5.5安装

(一)cmake语句

cmake -D CMAKE_INSTALL_PREFIX=/usr/local -D CMAKE_BUILD_TYPE=Release -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.5.5/modules ..

cmake -D CMAKE_BUILD_TYPE=RELEASE   -D CMAKE_INSTALL_PREFIX=/usr/local   -D WITH_TBB=ON -D WITH_V4L=ON   -D WITH_QT=ON   -D WITH_OPENGL=ON   -D WITH_CUDA=ON   -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1   -D CUDA_NVCC_FLAGS="-D_FORCE_INLINES"   -D WITH_CUBLAS=1 -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.5.5/modules/ -D CUDA_GENERATION=Kepler -D OPENCV_ENABLE_NONFREE=True -D CUDA_GENERATION=Pascal ..
sudo make -j8
sudo make install

(二)问题处理

1、主要面对的问题是下载问题

查看build文件夹下CMakeDownloadLog.txt,可以找到需要下载的文件,重新下载或者直接拷贝,将文件拷贝到opencv-4.5.5/.cache下指定的文件夹下,将名字改成未下载成功的缓存文件名,再执行cmake语句

2、error: ‘integer_sequence’ is not a member of ‘std’

找到报错的代码,在CmakeList.txt添加

set(CMAKE_CXX_STANDARD 14)

3、pkg-config opencv --modversion报错

在这里插入图片描述
cd /usr/local/lib
sudo mkdir pkgconfig
cd pkgconfig
sudo gedit opencv.pc
添加以下信息:

Package Information for pkg-config

prefix=/usr/local
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir_old=${prefix}/include/opencv4
includedir_new=${prefix}/include

Name: OpenCV
Description: Open Source Computer Vision Library
Version: 4.5.5
Libs: -L${exec_prefix}/lib -lopencv_cudabgsegm -lopencv_cudaobjdetect -lopencv_cudastereo -lopencv_stitching -lopencv_cudafeatures2d -lopencv_superres -lopencv_cudacodec -lopencv_videostab -lopencv_cudaoptflow -lopencv_cudalegacy -lopencv_cudawarping -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dnn_objdetect -lopencv_dpm -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_hdf -lopencv_hfs -lopencv_img_hash -lopencv_line_descriptor -lopencv_optflow -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_sfm -lopencv_stereo -lopencv_structured_light -lopencv_viz -lopencv_phase_unwrapping -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_dnn -lopencv_plot -lopencv_xfeatures2d -lopencv_shape -lopencv_video -lopencv_ml -lopencv_ximgproc -lopencv_xobjdetect -lopencv_objdetect -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_flann -lopencv_xphoto -lopencv_photo -lopencv_cudaimgproc -lopencv_cudafilters -lopencv_imgproc -lopencv_cudaarithm -lopencv_core -lopencv_cudev
Libs.private: -lm -lpthread -L//usr/lib/x86_64-linux-gnu -lGL -lGLU -lcudart_static -ldl -lrt -lnppc -lnppial -lnppicc -lnppicom -lnppidei -lnppif -lnppig -lnppim -lnppist -lnppisu -lnppitc -lnpps -lcublas -lcufft -L-L/usr/local/cuda -llib64 -L-L/usr/lib -lx86_64-linux-gnu
Cflags: -I${includedir_old} -I${includedir_new}

即可显示!

你可能感兴趣的:(软件安装,C++学习,计算机视觉,opencv,C++)