1. 程式人生 > >Ubuntu16.04安裝OpenCV3.2.0教程

Ubuntu16.04安裝OpenCV3.2.0教程

step 0
更新 apt-get(在安裝前最好先更新一下系統,不然可能會安裝失敗。)

sudo apt-get update
sudo apt-get upgrade

step 1
安裝依賴 (太多了,自己相應替換)

sudo apt-get -y install libopencv-dev build-essential cmake git libgtk2.0-dev pkg-config python-dev python-numpy libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libjasper-dev
libavcodec-dev libavformat-dev libswscale-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev libtbb-dev libqt4-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils unzip sudo apt-get -y install libopencv-dev
build-essential cmake git libgtk2.0-dev pkg-config python-dev python-numpy libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev libtbb-dev libqt4-dev libfaac-dev libmp3lame-dev
libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils unzip --fix-missing

step 2
下載並解包(手動下載快一些)

wget https://github.com/Itseez/opencv/archive/3.2.0.zip
unzip opencv-3.2.0.zip

step 3
編譯
在cmake下載過程中可能會出現 ICV:DOWNLONDING ippicv_linux_20151201.tgz 但是一直下載不下來,自己可以手動下載,把壓縮包放到opencv3.2.0->ippic->Download下

cd opencv-3.2.0
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D            CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..

step 4
安裝 (make 過程比較漫長,請耐心等待)

make 
sudo make install

step 5
安裝完成,進行整理

sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig
sudo apt-get update

step 6
測試是否安裝成功

python
>>> import cv2
>>> cv2.__version__
'3.2.0'
>>>

step 7
安裝成功