ubuntu anaconda 源码安装 opencv3 步骤

1. 下载opencv源码包

wget https://github.com/opencv/opencv/archive/3.2.0.zip
wget https://github.com/opencv/opencv_contrib/archive/3.2.0.zip
解压opencv-3.2.0,然后将opencv_contrib解压出来,并重命名为opencv_contrib,放到opencv-3.2.0文件夹下
 

2. 下载编译opencv所需文件包

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 # 处理图像所需的包
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev liblapacke-dev
sudo apt-get install libxvidcore-dev libx264-dev # 处理视频所需的包
sudo apt-get install libatlas-base-dev gfortran # 优化opencv功能
sudo apt-get install ffmpeg
3. cd到opencv-3.2.0文件夹下,mkdir build然后cd build,输入:

cmake -DBUILD_TIFF=ON -DBUILD_opencv_java=OFF -DWITH_CUDA=ON -DENABLE_AVX=ON -DWITH_LAPACK=OFF -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())") ..

4. cmake完成后,如果不报错,则可进行下一步:

make -j4

sudo make install

sudo ldconfig

5. 打开python,输入:
import cv2

若报如下错误:

“ImportError: /home/test2/anaconda3/lib/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /home/test2/anaconda3/lib/libopencv_objdetect.so.3.2)”

解决方法:

https://blog.csdn.net/Arthur_Holmes/article/details/89044780

cp /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21 /home/arthur/anaconda3/lib/libstdc++.so.6

cp /usr/lib/x86_64-linux-gnu/libstdc++.so.6 /home/test2/anaconda3/lib/libstdc++.so.6
 

你可能感兴趣的:(Linux,Python)