有时需要opencv2,有时需要opencv3.所以两个都安装在opt下面,需要的时候在cmake里指定。
opencv2 官方文档
$ cd /opt
$ sudo mkdir opencv2
$ cd ~/opencv-2.4.13
$ sudo apt-get install build-essential
$ sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
$ sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
$ mkdir release && cd release
$ cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/opt/opencv2 ..
$ make -j8
$ sudo make install
如果平时大多数情况用opencv2,可以在bashrc里加上下面这句,让cmake默认找到opencv2
export PKG_CONFIG_PATH=/opt/opencv2/lib/pkgconfig:${PKG_CONFIG_PATH}
opencv3
opencv3和cuda8不兼容。编译时需要修改~/opencv/modules/cudalegacy/src/graphcuts.cpp文件内容
#if !defined ( HAVE_CUDA) || defined (CUDA_DISABLER )
替换为
#if !defined ( HAVE_CUDA ) || defined (CUDA_DISABLER ) || (CUDART_VERSION >= 8000 )
然后其他的和opencv2一样。