1、GTK+2.x要先于OpenCV安装
sudoapt-get install build-essential cmakelibgtk2.0-devpkg-configlibavcodec-devlibavformat-devlibswscale-dev (如果无法定位软件包,换源)
2、在主文件夹下解压unzip -x opencv-3.0.0.zip
cd opencv-3.0.0
mkdir build
cd build
cmake ..
make
sudo make install
3、cmake之前的准备工作
用CMake,遇到个奇怪的问题:CMake Error at 3rdparty/ippicv/downloader.cmake:97 (message):
ICV: Failed to unpack ICV package from D:/Program
因为 linux安装opencv需要使用到的ippicv_linux_20141027.tgz安装包.因为墙的原因一直下载不下来.
手动下载后拷贝到opencv/3rdparty/ippicv/downloads/linux-8b449a536a2157bcad08a2b9f266828b/ 目录下即可,如果没有该 目录,则创建之。
下载网址在这里:http://osdn.jp/projects/sfnet_opencvlibrary/downloads/3rdparty/ippicv/ippicv_windows_20141027.zip/
4、make之前的准备工作
因为安装了cuda,所以需要设定好相关动态库,否则容易报错
添加pkg路径
sudo vim /etc/profile
然后在最后添加这样一句话:
export PKG_CONFIG_PATH=/usr/local/cuda-8.0/pkgconfig:/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
接着source /etc/profile
系统的动态库配置文件/etc/ld.so.conf没有将/usr/local/lib添加进去
sudo vim /etc/ld.so.conf
然后在最后添加
include /usr/local/lib
使用的是cuda8.0,需要修改源码,在path/opencv3.0.0/modules/cudalegacy/src/graphcuts.cpp中将
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER)
改为
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER) || (CUDART_VERSION >= 8000)
做完这些,编译
5、Ubuntu14.04安装好opencv3.0.0之后,进行测试:
cd opencv-3.0.0/samples/
sudo cmake .
sudo make –j $(nproc)
cd cpp
./cpp-example-facedetect girls.jpg //提前在文件夹放一张人笑脸的图片
如果出现问题CMakeError at CMakeLists.txt:3 (find_package):By not providing "FindOpenCV.cmake"in CMAKE_MODULE_PATH this project has asked CMaketo find a package configuration file provided by "OpenCV",but CMake didnot find one. Could not find a package configuration file provided by "OpenCV"with any of the following names: OpenCVConfig.cmakeopencv-config.cmakeAdd the installation prefix of "OpenCV"to CMAKE_PREFIX_PATH or set "OpenCV_DIR"to a directory containing one of the above files. If "OpenCV"provides a separate development package or SDK, be sure it has been installed.
则修改sample里面的CMakeLists.txt为:
set(OpenCV_DIR /home/用户名/opencv-3.0.0/build)
find_package(OpenCV REQUIRED )
在安装的opencv3.0.0的build里make uninstall
卸载不管用的话,直接到opencv解压目录把解压出的opencv包删掉
sudo rm -r release sudo rm -r /usr/local/include/opencv2 /usr/local/include/opencv /usr/include/opencv /usr/include/opencv2 /usr/local/share/opencv /usr/local/share/OpenCV /usr/share/opencv /usr/share/OpenCV /usr/local/bin/opencv* /usr/local/lib/libopencv//这一段可保留,make unstall后就清除了