直接采用别人在github上写好的脚本进行安装https://github.com/jayrambhia/Install-OpenCV。用其他方法安装容易出各种问题。
安装CUDA7.5,Ubuntu14.04,opencv2.4.10可以成功,安装步骤可参考下面。
安装opencv-2.4.10(opencv-2.4.13) in Ubuntu16.04 CUDA8.0不成功。
试过网上各种解决办法,看到有的让重装14.04系统,反正在此版本下没有安装成功。出现各种错误。
出现错误1:
make[2]: *** [modules/highgui/src/moc_window_QT.cxx] Error 1
CMakeFiles/Makefile2:2053: recipe for target 'modules/highgui/CMakeFiles/opencv_highgui.dir/all' failed
make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
make[1]: *** 正在等待未完成的任务....
[ 29%] Built target opencv_photo
[ 29%] Built target opencv_video
Makefile:149: recipe for target 'all' failed
make: *** [all] Error 2
出现错误2:
When I try to cmake to OpenCv-2.4.10 on Ubuntu16.04,I get this Error:
CMake Error: The following variables are used in this project, but they are set to NOTFOUND. Please set them or make sure they are set and tested correctly in the CMake files: CUDA_nvcuvid_LIBRARY (ADVANCED)
And then ,I disabled "with_cuda" option at CMakeLists.txt .After that,I get this warning:
The source directory is the same as binary directory. "make clean" may damage the source tree
The problem is that you need to create a link to libnvcuvid.so
located in/usr/lib/nvidia-current/
from/usr/lib/
.
do followings:
sudo su
su -c 'ln -s /usr/lib/nvidia-current/libnvcuvid.so /usr/lib/libnvcuvid.so && ln -s /usr/lib/nvidia-current/libnvcuvid.so.1 /usr/lib/libnvcuvid.so.1'
we can solve this problem.
出现错误3:make[2]: *** No rule to make target '/usr/lib/libnvcuvid.so', needed by 'lib/libopencv_gpu.so.2.4.13'。 停止。
CMakeFiles/Makefile2:4822: recipe for target 'modules/gpu/CMakeFiles/opencv_gpu.dir/all' failed
make[1]: *** [modules/gpu/CMakeFiles/opencv_gpu.dir/all] Error 2
Makefile:160: recipe for target 'all' failed
make: *** [all] Error 2
14.04下安装步骤,也会遇到一些问题,不过按照网上的办法修改,最后可以成功。
提前需要的依赖包:
GCC 4.4.x or later. This can be installed with:
CMake 2.6 or higher;
Git;
GTK+2.x or higher, including headers (libgtk2.0-dev);
pkg-config;
Python 2.6 or later and Numpy 1.5 or later with developer packages (python-dev, python-numpy);
ffmpeg or libav development packages: libavcodec-dev, libavformat-dev, libswscale-dev;
[optional] libdc1394 2.x;
[optional] libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev.
输入命令:
sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-config python-dev python-numpy libavcodec-dev libavformat-dev libswscale-dev libdc1394 2.x libjpeg-dev libpng-dev libtiff-dev libjasper-dev
sudo apt-get update
将opencv-2.4.10解压缩到当前目录:
unzip opencv-2.4.10.zip
用CMake创建OpenCV
cd ~/opencv-2.4.10
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_CUDA=ON -D ENABLE_FAST_MATH=ON -D CUDA_FAST_MATH=ON -D WITH_CUBLAS=1 -D WITH_NVCUVID=on -D CUDA_GENERATION=Auto ..
make -j8
make install
配置openCV参数设置
在/etc/ld.so.conf.d/opencv.conf文件中加入一行:/usr/local/lib ,
可能会没有opencv.conf这个文件,那我们就自己创建一个:
sudo gedit/etc/ld.so.conf.d/opencv.conf
使用下面这条命令:
sudo ldconfig
在 /etc/ bash.bashrc(sudo gedit/etc /bash.bashrc以root进入才能修改)中加入:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH