本文主要是介绍【opencv】安裝python接口,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
系統:ubuntu18.04LTS
python版本:python3.6
opencv版本:opencv4.0.0
其他部分按照 https://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html 这里进行即可,其中cmake命令执行如下:
cmake -D CMAKE_BUILD_TYPE=RELEASE \-D PYTHON3_EXECUTABLE=/usr/bin/python3.6 \-D PYTHON3_INCLUDE_DIR=/usr/include/python3.6 \-D PYTHON3_LIBRARY=/usr/lib/python3.6/config-3.6m-x86_64-linux-gnu/libpython3.6.so \-D PYTHON3_NUMPY_INCLUDE_DIR=/usr/local/lib/python3.6/dist-packages/numpy/core/include \-D PYTHON3_PACKAGES_PATH=/usr/local/lib/python3.6/dist-packages \-D CMAKE_INSTALL_PREFIX=/usr/local \-D BUILD_EXAMPLES=ON ..
这样安装完成后你应该能t通过测试文件:
<cmake_build_dir>/bin/opencv_test_core
但是在python3中import cv2依然会报找不到module。
按照 https://blog.csdn.net/taifengzikai/article/details/84671322 ,需要找到cv2.cpython-36m-x86_64-linux-gnu.so :
sudo find / -name "cv2.cpython-36m-x86_64-linux-gnu.so"
我的在:
/usr/local/python/cv2/python-3.6/cv2.cpython-36m-x86_64-linux-gnu.so
建立软链接即可:
cd /usr/local/python/cv2/python-3.6/
cd /usr/local/lib/python3.6/dist-packages/
sudo ln -s /usr/local/python/cv2/python-3.6/cv2.cpython-36m-x86_64-linux-gnu.so cv2.so
然后即可使用:
cd
python3
>>> import cv2
>>> cv2.__version__
'4.0.0'
这篇关于【opencv】安裝python接口的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!