当前位置:   article > 正文

Ubuntu 16.04编译Opencv 3.3.1 (For python2.7 and python3.5)_ubuntu编译opencv和opencv-contrib 是python2.7不是python3.

ubuntu编译opencv和opencv-contrib 是python2.7不是python3.8

       python安装opencv倒是快、方便,但有时要使用c++接口还的编译opencv,因此索性在配置opencv时从源码安装把c++、python2.7、python3的接口一次性配置好得了,免得以后用时又来折腾。虽然官网上也说了配置的一些选项https://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html,但感觉还是有人直接安装过那更好,但找了一圈发现好像只有这篇不错,https://blog.csdn.net/sonnyxin/article/details/83046141,我的配置还增加了contrib模块,其模块下载网站:https://github.com/opencv/opencv_contrib/releases,我的cmake配置大致如下:

因为我想使用ffmpeg库,所以首先的安装ffmpeg这个库,具体操作参考:

https://www.cnblogs.com/freeweb/p/6897907.html

如果ffmpeg 检查版本:ffmpeg -version出现 ffmpeg command not found解决办法

参考:https://blog.csdn.net/sinat_36458870/article/details/99719071

opencv_contrib模块放到当前opencv目录下

cd opencv

mkdir build

cd build

下面都在build目录下执行吧

1 安装必要的库

  1. sudo apt-get install build-essential
  2. sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
  3. sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

2 camke配置

  1. cmake -D CMAKE_BUILD_TYPE=RELEASE  \
  2.     -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-3.3.1/modules \
  3.     -D CMAKE_INSTALL_PREFIX=/usr/local \
  4.     -D INSTALL_C_EXAMPLES=OFF \
  5.     -D INSTALL_PYTHON_EXAMPLES=ON \
  6.     -D BUILD_EXAMPLES=OFF \
  7.     -D ENABLE_CXX11=ON \
  8. -D WITH_FFMPEG=1 \
  9. -D WITH_CUDA=ON \
  10.     -D BUILD_opencv_python3=ON  \
  11.     -D BUILD_opencv_python2=ON  \
  12.     -D PYTHON3_EXECUTABLE=$(which python3)\
  13.     -D PYTHON3_INCLUDE_DIR=/usr/include/python3.5m \
  14.     -D PYTHON3_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.5m.so.1 \
  15.     -D PYTHON3_NUMPY_PATH=/usr/local/lib/python3.5/dist-packages \
  16.     -D PYTHON2_EXECUTABLE=$(which python2)\
  17.     -D PYTHON2_INCLUDE_DIR=/usr/include/python2.7 \
  18.     -D PYTHON2_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython2.7.so.1 \
  19.     -D PYTHON2_NUMPY_PATH=/usr/local/lib/python2.7/dist-packages ..

3 make -j8 #根据自己电脑开启多个线程

4 sudo make install

编译opencv及contrib模块可能遇到问题及解决方法:

1opencv 找不到 feature2d/test/test_detectors_regression.impl.hpp 文件

参考:https://blog.csdn.net/u012939880/article/details/105864932#commentBox

  1. vim opencv/CMakeLists.txt
  2. 567 行添加:
  3. include_directories("modules")

编译OpenCV提示opencv_contrib缺少boostdesc_bgm.i等文件

参考:https://www.cnblogs.com/arxive/p/11778731.html

https://blog.csdn.net/u011736771/article/details/85960300

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/132744
推荐阅读
相关标签
  

闽ICP备14008679号