Ubuntu18.04+Anaconda3 cmake编译安装opencv4.2.0,亲测安装成功

尝试过用conda install安装opencv,命令简单安装速度也快,但是执行程序时会发生很多bug;也参考了很多cmake编译安装的教程,总是bug不断,折腾2天,综合了几篇教程,终于安装成功

一、安装Anacond3

参考博客https://blog.csdn.net/qq_15192373/article/details/81091098
安装成功后anaconda中的python应该就成为默认的python

二、安装依赖并下载opencv4.0

参考博客https://blog.csdn.net/new_delete_/article/details/84797041#commentBox
只需执行该博客中安装依赖和下载opencv这两个步骤,下载完成后解压

三、安装opencv

参考博客https://blog.csdn.net/xbean1028/article/details/91044640?utm_medium=distribute.pc_relevant.none-task-blog-baidujs-4
在参考这篇博客之前,每次cmake都会出现

missing PYTHON3_INCLUDE_DIR and PYTHON3_LIBRARY

或者

could not find Pythonlibs:Found unsuitable version

这篇博客会在cmake时指定python头文件和库的地址,避免了此类bug的出现

四、测试opencv

$ python3
Python 3.5.2 (default, Oct  8 2019, 13:06:37) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.

>>> import cv2 as cv
>>> print(cv.__version__)
4.1.1

若出现下面的bug:

ImportError: No module named cv2

可以参考“三、安装opencv”中博客末尾的处理办法,然后再次执行上面的python代码,运行正常即为安装opencv成功

五、参考文献

https://blog.csdn.net/qq_15192373/article/details/81091098
https://blog.csdn.net/new_delete_/article/details/84797041#commentBox
https://blog.csdn.net/xbean1028/article/details/91044640?utm_medium=distribute.pc_relevant.none-task-blog-baidujs-4

猜你喜欢

转载自blog.csdn.net/cxhmike/article/details/106603889