Python3.5.2是我長期使用的python穩(wěn)定版邪蛔,最近需要折騰opencv+contrib,把爬坑的步驟記下來以便日后查閱。
1.安裝基于Anaconda的python3.5.2
1.1 下載Anaconda
直接上鏈接:https://repo.continuum.io/archive/
找到Anaconda3-4.2.0-Linux-x86_64.sh
并下載
1.2 安裝
依次執(zhí)行并按提示操作:
$ sudo chmod +x Anaconda3-4.2.0-Linux-x86_64.sh
$ ./Anaconda3-4.2.0-Linux-x86_64.sh
安裝完成后的檢查:
$ python3
能進(jìn)入如下交互界面即可:
Python 3.5.2 |Anaconda 4.2.0 (64-bit)| (default ...)
[Gcc ...] on linux
Type "help", ...
>>>
2.安裝opencv+contrib
2.1 安裝依賴包
$ sudo apt-get install build-essential cmake pkg-config git
$ sudo apt-get install libjpeg8-dev libtiff5-dev libjasper-dev libpng12-dev libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev libgtk-3-dev libatlas-base-dev gfortran python2.7-dev python3.5-dev
2.2 克隆opencv以及opencv_contrib的源碼
$ git clone https://github.com/opencv/opencv.git
$ git clone https://github.com/opencv/opencv_contrib.git
2.3 cmake
$ cd opencv
$ mkdir build && cd build
$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_PYTHON_EXAMPLES=ON -D INSTALL_C_EXAMPLES=OFF -D OPENCV_EXTRA_MODULES_PATH=/home/dl0/opencv_contrib/modules -D PYTHON_EXECUTABLE=/home/dl0/anaconda3/bin/python3 -D BUILD_EXAMPLES=ON ..
其中:
-
OPENCV_EXTRA_MODULES_PATH
為contrib module 的路徑 -
PYTHON_EXECUTABLE
為python3.5.2的路徑
cmake成功后會有如下輸出:
...
-- Configuring done
-- Generating done
-- Build files have been written to: /home/dlo/opencv+contrib/opencv/build
其中/home/dlo/opencv+contrib/opencv/build
為build文件夾的完整路徑
2.4 編譯安裝
#進(jìn)入剛才的build目錄
$ cd build
$ make -j7
$ sudo make install
安裝完成后,重命名Anaconda3安裝目錄下/home/dl0/anaconda3/lib/python3.5/site-packages
的cv2.cpython-35m-x86_64-linux-gnu.so
:
$ mv /home/dl0/anaconda3/lib/python3.5/site-packages/cv2.cpython-35m-x86_64-linux-gnu.so /home/dl0/anaconda3/lib/python3.5/site-packages/cv2.so
2.5 測試
$ python3
Python 3.5.2 |Anaconda 4.2.0 (64-bit)| (default ...)
[Gcc ...] on linux
Type "help", ...
>>>import cv2
>>>print(cv2.__version__)
3.4.1
至此安裝完畢。安裝過程中會遇到各種各樣的坑尼荆,也希望遇到的朋友能分享一下各種爬坑經(jīng)驗。
感謝你的耐心閱讀仁锯,謝謝
:)