opencv下载:http://wiki.opencv.org.cn/index.php/Download
本文在Linux上适用,QT版本什么都可以,opencv版本什么都可以,linux内核2.6以上
一,opencv 安装
1.其他安装所需要的包的安装
GCC 4.4.x或更高
CMKE2.8.7或更高
Git
GTK+2.x或更高
pkg-config
Python2.6或更高,Numpy1.5或更高和开发包(python-dev,python-numpy)
ffmpeg或者libav开发包:libavcodec-dev, libavformat-dev, libswscale-dev
可选包:libtbb2 ,libtbb-dev
可选包:libdc1394 2.x
可选包:libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev, libdc1394-22-dev
必须:#
sudoapt-get
install
build-essential
必须:#
sudo
apt-get
install
cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswsc
可选:#sudo
apt-get
install
python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
2.opencv下载(下载最新版本)
http://www.opencv.org.cn/index.php/Download
解压安装包 (unzip或者windows下解压)
#sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=
/usr/local
..
或者使用cmake-gui用图形界面编译。
『配置时出现以下错误 -- ICV: Downloading ippicv_linux_20151201.tgz...』
解决方案:
首先,手动下载[ippicv](https://raw.githubusercontent.com/Itseez/opencv_3rdparty/81a676001ca8075ada498583e4166079e5744668/ippicv/ippicv_linux_20151201.tgz)
然后,将刚才下载的ippicv文件直接拷贝进入opencv3.1源码的下面这个目录:
opencv-3.1.0/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e
最后一个目录可能不一样,但无所谓。
最后再使用命令编译:
#cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local .. 这个问题是下载ippicv_linux_20151201.tgz时的校验和不符,查看了配置文件,可以自行从 http://sourceforge.net/projects/opencvlibrary/files/3rdparty/ippicv这里下载所需额版本,将下载的文件
opencv-3.1.0/3rdparty/ippicv/downloads/linux-8b449a536a2157bcad08a2b9f266828b ,代替原来的同名文件,ok问题解决
6.进行编译
或者
#sudo make -j $(nproc)
正确编译结果是:
<code class="hljs avrasm has-numbering">[<span class="hljs-number">100</span>%] Building CXX object apps/traincascade/CMakeFiles/opencv_traincascade<span class="hljs-preprocessor">.dir</span>/traincascade<span class="hljs-preprocessor">.cpp</span><span class="hljs-preprocessor">.o</span> [<span class="hljs-number">100</span>%] Building CXX object apps/traincascade/CMakeFiles/opencv_traincascade<span class="hljs-preprocessor">.dir</span>/cascadeclassifier<span class="hljs-preprocessor">.cpp</span><span class="hljs-preprocessor">.o</span> [<span class="hljs-number">100</span>%] Building CXX object apps/traincascade/CMakeFiles/opencv_traincascade<span class="hljs-preprocessor">.dir</span>/boost<span class="hljs-preprocessor">.cpp</span><span class="hljs-preprocessor">.o</span> [<span class="hljs-number">100</span>%] Building CXX object apps/traincascade/CMakeFiles/opencv_traincascade<span class="hljs-preprocessor">.dir</span>/features<span class="hljs-preprocessor">.cpp</span><span class="hljs-preprocessor">.o</span> [<span class="hljs-number">100</span>%] Building CXX object apps/traincascade/CMakeFiles/opencv_traincascade<span class="hljs-preprocessor">.dir</span>/haarfeatures<span class="hljs-preprocessor">.cpp</span><span class="hljs-preprocessor">.o</span> [<span class="hljs-number">100</span>%] Building CXX object apps/traincascade/CMakeFiles/opencv_traincascade<span class="hljs-preprocessor">.dir</span>/lbpfeatures<span class="hljs-preprocessor">.cpp</span><span class="hljs-preprocessor">.o</span> [<span class="hljs-number">100</span>%] Building CXX object apps/traincascade/CMakeFiles/opencv_traincascade<span class="hljs-preprocessor">.dir</span>/HOGfeatures<span class="hljs-preprocessor">.cpp</span><span class="hljs-preprocessor">.o</span> [<span class="hljs-number">100</span>%] Building CXX object apps/traincascade/CMakeFiles/opencv_traincascade<span class="hljs-preprocessor">.dir</span>/imagestorage<span class="hljs-preprocessor">.cpp</span><span class="hljs-preprocessor">.o</span> Linking CXX executable ../../bin/opencv_traincascade </code>
正确的结果提示是:
<code class="hljs haml has-numbering">... -<span class="ruby">- <span class="hljs-constant">Set</span> runtime path of <span class="hljs-string">"/usr/local/bin/opencv_haartraining"</span> to <span class="hljs-string">"/usr/local/lib"</span> </span>-<span class="ruby">- <span class="hljs-constant">Installing</span><span class="hljs-symbol">:</span> /usr/local/bin/opencv_createsamples </span>-<span class="ruby">- <span class="hljs-constant">Set</span> runtime path of <span class="hljs-string">"/usr/local/bin/opencv_createsamples"</span> to <span class="hljs-string">"/usr/local/lib"</span> </span>-<span class="ruby">- <span class="hljs-constant">Installing</span><span class="hljs-symbol">:</span> /usr/local/bin/opencv_performance </span>-<span class="ruby">- <span class="hljs-constant">Set</span> runtime path of <span class="hljs-string">"/usr/local/bin/opencv_performance"</span> to <span class="hljs-string">"/usr/local/lib"</span> </span>-<span class="ruby">- <span class="hljs-constant">Installing</span><span class="hljs-symbol">:</span> /usr/local/bin/opencv_traincascade </span>-<span class="ruby">- <span class="hljs-constant">Set</span> runtime path of <span class="hljs-string">"/usr/local/bin/opencv_traincascade"</span> to <span class="hljs-string">"/usr/local/lib"</span></span></code><a target=_blank name="t11"></a>
<code class="hljs avrasm has-numbering">查看已经生成的动态库 root@noya-VirtualBox:/usr/local/lib<span class="hljs-preprocessor"># ls</span> libopencv_calib3d<span class="hljs-preprocessor">.so</span> libopencv_gpu<span class="hljs-preprocessor">.so</span> libopencv_nonfree<span class="hljs-preprocessor">.so</span> libopencv_superres<span class="hljs-preprocessor">.so</span> libopencv_calib3d<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span> libopencv_gpu<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span> libopencv_nonfree<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span> libopencv_superres<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span> libopencv_calib3d<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span><span class="hljs-number">.9</span> libopencv_gpu<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span><span class="hljs-number">.9</span> libopencv_nonfree<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span><span class="hljs-number">.9</span> libopencv_superres<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span><span class="hljs-number">.9</span> libopencv_contrib<span class="hljs-preprocessor">.so</span> libopencv_highgui<span class="hljs-preprocessor">.so</span> libopencv_objdetect<span class="hljs-preprocessor">.so</span> libopencv_ts<span class="hljs-preprocessor">.a</span> libopencv_contrib<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span> libopencv_highgui<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span> libopencv_objdetect<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span> libopencv_video<span class="hljs-preprocessor">.so</span> libopencv_contrib<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span><span class="hljs-number">.9</span> libopencv_highgui<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span><span class="hljs-number">.9</span> libopencv_objdetect<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span><span class="hljs-number">.9</span> libopencv_video<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span> libopencv_core<span class="hljs-preprocessor">.so</span> libopencv_imgproc<span class="hljs-preprocessor">.so</span> libopencv_ocl<span class="hljs-preprocessor">.so</span> libopencv_video<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span><span class="hljs-number">.9</span> libopencv_core<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span> libopencv_imgproc<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span> libopencv_ocl<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span> libopencv_videostab<span class="hljs-preprocessor">.so</span> libopencv_core<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span><span class="hljs-number">.9</span> libopencv_imgproc<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span><span class="hljs-number">.9</span> libopencv_ocl<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span><span class="hljs-number">.9</span> libopencv_videostab<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span> libopencv_features2d<span class="hljs-preprocessor">.so</span> libopencv_legacy<span class="hljs-preprocessor">.so</span> libopencv_photo<span class="hljs-preprocessor">.so</span> libopencv_videostab<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span><span class="hljs-number">.9</span> libopencv_features2d<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span> libopencv_legacy<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span> libopencv_photo<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span> pkgconfig libopencv_features2d<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span><span class="hljs-number">.9</span> libopencv_legacy<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span><span class="hljs-number">.9</span> libopencv_photo<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span><span class="hljs-number">.9</span> python2<span class="hljs-number">.7</span> libopencv_flann<span class="hljs-preprocessor">.so</span> libopencv_ml<span class="hljs-preprocessor">.so</span> libopencv_stitching<span class="hljs-preprocessor">.so</span> libopencv_flann<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span> libopencv_ml<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span> libopencv_stitching<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span> libopencv_flann<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span><span class="hljs-number">.9</span> libopencv_ml<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span><span class="hljs-number">.9</span> libopencv_stitching<span class="hljs-preprocessor">.so</span><span class="hljs-number">.2</span><span class="hljs-number">.4</span><span class="hljs-number">.9</span></code>
使用下面的动态库管理命令ldconfig,让opencv的相关链接库被系统共享
#sudo ldconfig -v<span style="color:#990000;"><code class="hljs ruby has-numbering">export <span class="hljs-constant">PKG_CONFIG_PATH</span>=<span class="hljs-variable">$PKG_CONFIG_PATH</span><span class="hljs-symbol">:/usr/local/lib/pkgconfig</span> </code></span>
pkg-config 维护着一个关于opencv的配置文件,这个文件(opencv.pc)在目录 /usr/local/lib/pkgconfig,这个文件记录着opencv的一些动态库信息,还有头文件信息
输入pkg-config --cflags opencv 和pkg-config --libs opencv ,可以发现以下信息。
正确的结果是如下:
sjj@sjj-QiTianM4500-N000:/usr/local/opencv-3.1.0/release$ pkg-config --cflags opencv
-I/usr/local/include/opencv -I/usr/local/include
sjj@sjj-QiTianM4500-N000:/usr/local/opencv-3.1.0/release$ pkg-config --libs opencv
-L/usr/local/lib -lopencv_calib3d -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_video -lopencv_videoio -lopencv_videostab
配置信息:pkg-config --cflags opencv
ldconfig(这一步很重要)