赞
踩
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 安装必要的库
- 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
2 camke配置
- cmake -D CMAKE_BUILD_TYPE=RELEASE \
- -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-3.3.1/modules \
- -D CMAKE_INSTALL_PREFIX=/usr/local \
- -D INSTALL_C_EXAMPLES=OFF \
- -D INSTALL_PYTHON_EXAMPLES=ON \
- -D BUILD_EXAMPLES=OFF \
- -D ENABLE_CXX11=ON \
- -D WITH_FFMPEG=1 \
- -D WITH_CUDA=ON \
- -D BUILD_opencv_python3=ON \
- -D BUILD_opencv_python2=ON \
- -D PYTHON3_EXECUTABLE=$(which python3)\
- -D PYTHON3_INCLUDE_DIR=/usr/include/python3.5m \
- -D PYTHON3_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.5m.so.1 \
- -D PYTHON3_NUMPY_PATH=/usr/local/lib/python3.5/dist-packages \
- -D PYTHON2_EXECUTABLE=$(which python2)\
- -D PYTHON2_INCLUDE_DIR=/usr/include/python2.7 \
- -D PYTHON2_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython2.7.so.1 \
- -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
- vim opencv/CMakeLists.txt
- 在 567 行添加:
- include_directories("modules")
2编译OpenCV提示opencv_contrib缺少boostdesc_bgm.i等文件
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。