Ubuntu16.04+OpenCV3.2.0+Opencv_Contrib3.2.0安装

时间:2024-03-23 19:05:38

为了学习slam,在ubuntu16.04系统上安装opencv3.2.0以及对应的opencv_contrib3.2.0

安装过程


下载

Github上下载有的时候比较慢,我这里分享了OpenCV3.2.0+OpenCV_contrib3.2.0的下载链接(包括一些编译过程中需要下载的文件)

链接:Download 提取码:8jaw

安装opencv依赖库

$ sudo apt-get install build-essential

$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev

$ sudo apt-get -install libgtk2.0-dev pkg-config python-dev python-numpy libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libtiff5-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libxine2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev libtbb-dev libqt4-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev 

事实上,OpenCV的依赖库很多,缺失某些项编译的时候会出错或者影响某些功能。OpenCV会在cmake的时候检查依赖项是否安装,如果出错,按照提示安装依赖项即可。

解压opencv-3.2.0文件

$ unzip opencv-3.2.0.zip     //我这里当前文件路径为 /Downloads

解压opencv_contrib-3.2.0.tar.gz

$ tar -zxvf opencv_contrib-3.2.0.tar.gz -C ./opencv-3.2.0/

编译

$ cd opencv-3.2.0/
$ mkdir build
$ cd build $ cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=/home/ai/downloads/opencv-3.2.0/opencv_contrib-3.2.0/modules/ -D WITH_TBB=ON -D BUILD_SHARED_LIBS=OFF -D WITH_OPENMP=OFF -D ENABLE_PRECOMPILED_HEADERS=OFF ..

安装

$ sudo make -j8   //多线程
$ sudo make install

配置环境

$ sudo gedit /etc/ld.so.conf.d/opencv.conf

# 在最后一行添加 /usr/local/lib

$ sudo gedit /etc/bash.bashrc

# 在最后一行中添加:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/opencv320/lib/pkgconfig
export PKG_CONFIG_PATH $ sudo ldconfig $ sudo cp /usr/local/lib/pkgconfig/opencv.pc /usr/lib/pkgconfig

最后安装成功

$ pkg-config --modversion opencv

遇到的问题


1. 下载ippicv_linux_20151201.tgz超时

解决方案:手动下载

如果终端下载过慢,或者出现超时。上面的下载包里有这个压缩文件,把这个压缩文件放入/opencv-3.2.0/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e/夹中。(严格来说,是放入错误提示的文件路径)

2. 缺少gtk+-3.0

No package 'gtk+-3.0' found

解决方案:

$ sudo apt-get install libgtk-3-dev

3. 缺少依赖项

--   No package 'gstreamer-base-1.0' found

--   No package 'gstreamer-video-1.0' found

--   No package 'gstreamer-app-1.0' found

--   No package 'gstreamer-riff-1.0' found

--   No package 'gstreamer-pbutils-1.0' found

解决方案:

$ sudo apt-get install libgstreamer0.10-dev
$ sudo apt-get install libgstreamer-plugins-base0.10-dev
$ sudo apt-get install libgstreamer1.0-dev
$ sudo apt-get install libgstreamer-plugins-base1.0-dev $ sudo apt-get install libgstreamer1.0-dev
$ sudo apt-get install libgstreamer-plugins-base0.10-dev
$ sudo apt-get install libgstreamer0.10-dev
$ sudo apt-get install libgstreamer-plugins-base1.0-dev

如果下载这些依赖这些包的时候,出现无法定位软件包,应该是系统的源的有问题,可以换其他源,我后面改用阿里的源可以成功下载依赖项。

3. 缺少libavresample、libgphoto2包

--   No package 'libavresample' found

--   No package 'libgphoto2' found

解决方案:

$ sudo apt-get install libavresample-dev
$ sudo apt-get install libgphoto2-dev

4. 缺少libavresample包

--   No package 'libavresample' found

解决方案:

$ sudo apt-get install libavresample-dev
$ sudo apt-get install libgphoto2-dev

5. 找不到OpenBLAS include

-- Could not find OpenBLAS include. Turning OpenBLAS_FOUND off
-- Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off

解决方案:

$ sudo apt-get install libopenblas-dev

6. 找不到Doxygen include

-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)

解决方案:

$ sudo apt-get install doxygen

7. 找不到JNI

-- Could NOT find JNI (missing: JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)

解决方案:

详见参考[1]

8. make的时候缺失opencv_lapack.h

解决方案:

$ sudo apt-get install liblapacke-dev checkinstall

9.提示no package opencv found

pkg-config --modversion opencv 的时候提示找不到opencv包

解决方案:

配置环境时缺少了一行代码:

$ sudo cp /usr/local/opencv320/lib/pkgconfig/opencv.pc /usr/lib/pkgconfig

10.出现Makefile:160: recipe for target 'all' failed

解决方案:

opencv_contrib的路径有问题,在编译时候最好指定opencv_contrib的文件路径,否则会在make的时候出现makefile找不到的问题。

参考

[1] https://blog.csdn.net/weixin_41896508/article/details/80795239

[2] https://blog.csdn.net/qq_29229045/article/details/78527391