$ sudo apt-get update
$ sudo apt-get upgrade
apt-get update
- 更新最新的套件資訊
apt-get upgrade
- 更新套件
安裝基本開發工具
$ sudo apt-get install build-essential cmake pkg-config git
- build-essential - 基本編譯器
- git - 分散式的版本控制系統
- cmake - 跨平台自動化建構系統
- pkg-config - 查詢套件include與library的位置
安裝影像I/O開發工具,例:JPEG, PNG, TIFF, etc.
$ sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
- libjpeg-dev - (Joint Photographic Experts Group)一種失真壓縮標準方法
- libtiff5-dev - (Tagged Image File Format)標籤圖檔格式
- libpng12-dev - (Portable Network Graphics)可攜式網路圖形
- libjasper-dev
安裝影音I/O開發工具,讀影影片、接收串流、影音解碼...
$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev
- libavcodec-dev - 影音編碼與解碼 ( encoding and decoding of audio, video )
- libavformat-dev - 影音格式解析 ( muxing and demuxing containers )
- libswscale-dev - 影像縮放、色彩空間轉換
- libv4l-dev -
- libxvidcore-dev -
- libx264-dev - H.264 / MPEG-4 AVC 編碼器
安裝GTK開發工具,OpenCV highgui module顯示視窗時需要
$ sudo apt-get install libgtk2.0-dev
- libgtk2.0-dev - (Gimp ToolKit)跨平台的圖形介面開發套件
$ sudo apt-get install libtbb-dev
- libtbb-dev - (Intel® Threading Building Blocks )平行計算引擎
安裝OpenCV優化的開發工具
$ sudo apt-get install libatlas-base-dev gfortran
- gfortran - (Formula Translation)高級編程語言
- libatlas-base-dev -
安裝Python 2.7 及 Python 3 header檔,OpenCV + Python bindings時需要
$ sudo apt-get install python2.7-dev python3-dev
下載OpenCV原始碼
$ git clone https://github.com/Itseez/opencv.git
$ cd opencv
$ git checkout 3.1.0
多個特徵擷取被移至contrib
$ git clone https://github.com/Itseez/opencv_contrib.git
$ cd opencv_contrib
$ git checkout 3.1.0
編譯
$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
-D BUILD_EXAMPLES=ON ..
$ make -j4
$ sudo make install
$ sudo ldconfig
Install
$ sudo pip install virtualenv virtualenvwrapper
$ sudo rm -rf ~/.cache/pip
Update our ~/.bashrc
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
$ source ~/.bashrc
$ mkvirtualenv cv
$WORKON_HOME製作虛擬環境
$ mkvirtualenv [-i package] [-r requirements_file] [virtualenv options] ENVNAME
列出所有的虛擬環境
$ lsvirtualenv [-b] [-l] [-h]
-b
是簡短模式-l
是詳細模式-h
是印出 help 資訊
移除虛擬環境
$ rmvirtualenv ENVNAME
啟動虛擬環境
$ workon [environment_name]
離開虛擬環境
$ deactivate
- virtualenv - Virtual Python Environment builder
- virtualenvwrapper -
確認Python與OpenCV使否已經設定完成 For Python 2.7:
$ ls -l /usr/local/lib/python2.7/site-packages/
total 1440
-rw-r--r-- 1 root staff 1473028 Dec 7 04:10 cv2.so
連結opencv與cv虛擬環境
$ cd ~/.virtualenvs/cv/lib/python2.7/site-packages/
$ ln -s /usr/local/lib/python2.7/site-packages/cv2.so cv2.so
$ workon cv
$ python
>>> import cv2
>>> cv2.__version__
'3.1.0'