安裝過程主要是參考了這一篇的步驟,基本上沒有甚麼特別需要注意的地方,一步一步照著做下來就是了
依照步驟安裝完成後,因為我所使用的是Raspberry Pi的Camera模組(而非USB CAM);因此需要多執行一步pip install PiCamera[Array]讓Python與OpenCV能夠存取Pi Camera模組
安裝完成後,需要跑個Sample Code試試看是否安裝正確;網路上有很多sample code,如果有興趣,也可以拿之前日本工程師寫的老闆偵測器(BossSensor)試試看。
這裡是一個支援OpenCV 3.1.0以上版本的測試程式:https://github.com/michael-chi/OpenCVSample;測試結果如下:
Update apt-get:
$ sudo rpi-update
$ sudo apt-get update
$ sudo apt-get upgrade
Install developer tools:
$ sudo apt-get install build-essential cmake cmake-curses-gui pkg-config
Install required libraries:
$ sudo apt-get install \
libjpeg-dev \
libtiff5-dev \
libjasper-dev \
libpng12-dev \
libavcodec-dev \
libavformat-dev \
libswscale-dev \
libeigen3-dev \
libxvidcore-dev \
libx264-dev \
libgtk2.0-dev
Install libraries used to optimize OpenCV:
$ sudo apt-get install libatlas-base-dev gfortran
Install Python development libraries & Numpy:
$ sudo apt-get install python2.7-dev
$ sudo apt-get install python3-dev
Install Numpy:
$ pip install numpy
$ pip3 install numpy
Create a directory to home OpenCV and enter it:
$ mkdir opencv && cd opencv
Checkout current OpenCV 3.2.0 & the contribs:
$ wget https://github.com/opencv/opencv/archive/3.2.0.zip -O opencv_source.zip
$ wget https://github.com/opencv/opencv_contrib/archive/3.2.0.zip -O opencv_contrib.zip
Unzip the code:
$ unzip opencv_source.zip
$ unzip opencv_contrib.zip
Move into the 3.2.0 directory, make the build dir and move into it:
$ cd ~/opencv/opencv-3.2.0 && mkdir build && cd build
Configure the build:
$ sudo cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D BUILD_WITH_DEBUG_INFO=OFF \
-D BUILD_DOCS=OFF \
-D BUILD_EXAMPLES=OFF \
-D BUILD_TESTS=OFF \
-D BUILD_opencv_ts=OFF \
-D BUILD_PERF_TESTS=OFF \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-3.2.0/modules \
-D ENABLE_NEON=ON \
-D WITH_LIBV4L=ON \
../
If everything went ok you should see the following:
-- Configuring done
-- Generating done
Build OpenCV, grab a beer as this will take a while, come back and check at intervals to see if there has been any errors:
$ sudo make -j4
Once complete you should see the following:
[100%] Built target ...
Install OpenCV:
$ sudo make install
$ sudo ldconfig
Test the installation:
$ python/python3
>> import cv2
>> print (cv2.__version__)
>> import face
沒有留言:
張貼留言