opencv3.2 安裝說(shuō)明書

opencv3.2 安裝說(shuō)明書

軟件環(huán)境

ubuntu 14,04 python2.7 cmake , g++, gcc

1 安裝OpenCV依賴

1.1 升級(jí)系統(tǒng)

$ sudo apt-get update

$ sudo apt-get upgrade

1.2 安裝編譯工具

由于是通過(guò)源代碼安裝 , 說(shuō)以需要安裝編譯工具.

$ sudo apt-get install build-essential cmake pkg-config

1.3 安裝依賴庫(kù)

由于OpenCV是計(jì)算機(jī)視覺庫(kù),總需要加載一些圖像文件( JPEG, PNG, TIFF)。使用下面命令安裝一些必要的圖像庫(kù):

$ sudo apt-get install libjpeg8-dev libtiff5-dev libjasper-dev libpng12-dev

除了圖片之外,OpenCV還要處理視頻文件。使用下面命令安裝一些視頻編解碼庫(kù)

sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev

sudo apt-get install libxvidcore-dev libx264-dev

OpenCV的GUI模塊highgui依賴Gtk。安裝gtk庫(kù):

sudo apt-get install libgtk-3-dev

下面安裝一些可以提高OpenCV性能的庫(kù),如矩陣操作:

sudo apt-get install libatlas-base-dev gfortran

安裝Python2和Python3的開發(fā)庫(kù):

sudo apt-get install python2.7-dev python3.5-dev

PS Ubuntu14.04中含有python2.7 , 如果不想自己的系統(tǒng)環(huán)境太復(fù)雜,可以選擇不去安裝python2.7

下載opencv 源代碼

目前OpenCV的最新穩(wěn)定版是3.2 , 可以去opencv官網(wǎng)上下載, 也可以去github總下載最新版本

最好再下載opencv_contrib,

opencvcontrib模塊是Opencv 沒(méi)有經(jīng)過(guò)足夠測(cè)試的的新功能模塊.OpenCV 在發(fā)布新的版本之前,首先在opencvcontrib倉(cāng)庫(kù)中發(fā)布。當(dāng)模塊成熟并獲得普及后,便轉(zhuǎn)移到中央OpenCV存儲(chǔ)庫(kù),并發(fā)布新的版本; :)

注意:opencv和opencv_contrib的版本要一致

# 由于我下載的opencv3.2? 所以會(huì)在github下找到相應(yīng)的版本

wget https://github.com/opencv/opencv_contrib/archive/3.2.0.tar.gz

tar -zvxf 3.2.0.tar.gz? # 解壓以后生成 opencv_contrib-3.2.0

2. 編譯OpenCV

切換到opencv 的build 目錄 , opencvbuilddirectory

cd ? ## 跳轉(zhuǎn)到opencv 目錄

mkdir build? ## 創(chuàng)建 opencv_build_directory

cd ? ## 切換到 opencv_build_directory 目錄

生成編譯文件

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/linux/work_space/opencv_contribute/opencv_contrib-3.2.0/modules \

-D PYTHON_EXECUTABLE=/usr/bin/python2.7 -D BUILD_EXAMPLES=ON ..

make -j? ? #NUM 自己設(shè)定? 我設(shè)置的是80

ps: 我這里opencvcontrib 的目錄是/home/linux/workspace/opencvcontribute/opencvcontrib-3.2.0/ ; 所以參數(shù)寫成 -D OPENCVEXTRAMODULESPATH=/home/linux/workspace/opencvcontribute/opencvcontrib-3.2.0/modules

最后的 .. ?是由于build 目錄在openCV里面, 我想編譯build 外面的文件,所以要用相對(duì)路徑 ..?


如果是MacOS? 可以采用以下方式編譯:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local \

-D PYTHON2_PACKAGES_PATH=/usr/local/lib/python2.7/site-packages \

-D PYTHON2_LIBRARY=/Library/Frameworks/Python.framework/Versions/2.7/bin \

-D PYTHON2_INCLUDE_DIR=/Library/Frameworks/Python.framework/Headers \

-D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON \

-D BUILD_EXAMPLES=ON \

-D OPENCV_EXTRA_MODULES_PATH=/Users/lee/workspace/opencv_contrib-3.2.0/modules ..


參數(shù)說(shuō)明:

There are somevery importantoptions we are supplying to CMake here, so let’s break them down:

CMAKE_BUILD_TYPE: This option indicates that we are building a release binary of OpenCV.

CMAKE_INSTALL_PREFIX: The base directory where OpenCV will be installed.

PYTHON2_PACKAGES_PATH: Theexplicitpath to where oursite-packagesdirectory lives in ourcvvirtual environment.

PYTHON2_LIBRARY: Path to our Hombrew installation of Python.

PYTHON2_INCLUDE_DIR: The path to our Python header files for compilation.

INSTALL_C_EXAMPLES: Indicate that we want to install the C/C++ examples after compilation.

INSTALL_PYTHON_EXAMPLES: Indicate that we want to install the Python examples after complication.

BUILD_EXAMPLES: A flag that determines whether or not the included OpenCV examples will be compiled or not.

OPENCV_EXTRA_MODULES_PATH:This option is?extremely important— here we supply the path to theopencv_contribrepo that we pulled down earlier, indicating that OpenCV should compile the extra modules as well.



3 安裝

make install #? 安裝

3.1 Mac OS

PS: 如果你是MacOS 那么還需要手動(dòng)的添加cv2的相關(guān)文件到python 中;

我這里提供兩種方式:

如果使用brew 安裝的, (安裝步驟詳見?)僅需如此:

查看有沒(méi)有這個(gè)目錄?? /usr/local/Cellar/opencv/2.4.10/

cd /Library/Python/2.7/site-packages/

ln -s /usr/local/Cellar/opencv/2.4.13.2/lib/python2.7/site-packages/cv.py cv.py

ln -s /usr/local/Cellar/opencv/2.4.13.2/lib/python2.7/site-packages/cv2.so cv2.so




如果是安裝以上的源碼方式在本地編譯安裝的情況:


sudo ln -s /usr/local/Cellar/opencv/2.4.13.2/lib/python2.7/site-packages/cv2.so
/Library/Python/2.7/site-packages/cv2.so

?即可


?




4 參考文獻(xiàn)

在mac上安裝opencv 與python?

ubuntu opencv3.1

opencv-3-0-trouble-with-installation

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容