Ubuntu上用anaconda3安装opencv3
由于opencv网上大多数教程是依赖于python2.7的安装的,很少有基于python3.x的,所以本教程旨在讲解如何在Ubuntu下使用anaconda3安装opencv3。 我的系统环境: Ubuntu 16.04、Anaconda 3.5.2(也就是python 3.5.2)、安装opencv 3.2.0 具体步骤如下: 1、从opencv官网下载opencv 3.2.0 2、安装必要的库:
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
3、解压安装包:unzip 3*.zip 4、进入解压后的目录:
cd /opencv* 5、创建一个release目录:
6、进入release目录:mkdir release
cd release 7、也是安装的最关键的一步,如果是在python2.7中安装opencv是没有这步,这步也是所有步骤的精华之处(仅一句,因书写方便换行):
参考网站:https://www.scivision.co/anaconda-python-opencv3/8、编译:cmake -DBUILD_TIFF=ON -DBUILD_opencv_java=OFF -DWITH_CUDA=OFF -DENABLE_AVX=ON -DWITH_OPENGL=ON -DWITH_OPENCL=ON -DWITH_IPP=ON -DWITH_TBB=ON -DWITH_EIGEN=ON -DWITH_V4L=ON -DWITH_VTK=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_opencv_python2=OFF -DCMAKE_INSTALL_PREFIX=$(python3 -c "import sys; print(sys.prefix)") -DPYTHON3_EXECUTABLE=$(which python3) -DPYTHON3_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") -DPYTHON3_PACKAGES_PATH=$(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") ..
9、编译执行:make -j4 (注意:如果在后面make install出错,可以试试make -j1)
make install # 如果权限不够可尝试sudo make install
他大爷的,我最讨厌装这些难装的库了,又出现bug了,问题如下:>>> import cv2 Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: /home/topplus/anaconda3/lib/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by /home/topplus/anaconda3/lib/python3.6/site-packages/cv2.cpython-36m-x86_64-linux-gnu.so)
最后才百度到的解决方案:
打开终端输入命令:pip install opencv-python
不过还可能出现以下问题:截图如下:error: (-2) The function is not implemented. Rebuild the library withWindows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian,install libgtk2.0-dev and pkg-config, then re-run cmake or configurescript in function cvShowImage
最后卸载了各种库再安装,还是一样的问题——import cv2没问题, 但是一运行程序就有问题。
所以我只能连同anaconda也一起卸载了,然后再用的我另一篇博客写的安装opencv简要方法, 才算成功。。。唉,蛋疼!
我已经哭了......最后,再次打开终端, import终于成功了!
我就是按照上述教程安装上opencv的,亲测!
https://blog.kevin-brown.com/programming/2014/09/27/building-and-installing-opencv-3.html