Raspberry Pi Lane Tracking Car — install OpenCV

OpenCV簡介

OpenCV是一個開放原始碼的電腦視覺程式庫,可以用來做影像處理

接下來會利用RPi處理影像以辨識車道的位置,因此要在RPi上安裝OpenCV

安裝步驟

登入RPi終端機後,按造順序輸入以下指令:

sudo apt-get update
sudo apt-get upgrade

安裝相關套件

sudo apt-get install build-essential cmake pkg-config libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev libgtk2.0-dev libatlas-base-dev gfortran python2.7-dev python3-dev python3-pip python3-numpy git

其中 libjpeg-dev, libtiff5-dev, libjasper-dev, libpng12-dev 是讓opencv可以讀取jpg, png, tiff等照片格式、libavcodec-dev, libavformat-dev, libswscale-dev, libv4l-dev, libxvidcore-dev, libx264-dev 是影像串流相關的程式庫,以及libgtk2.0-dev用來顯示畫面等

從原始碼編譯、安裝OpenCV 3

下載OpenCV及contrib的原始碼

wget -O opencv https://github.com/opencv/opencv/archive/3.2.0.zip
wget -O opencv_contrib https://github.com/opencv/opencv_contrib/archive/3.2.0.zip

unzip opencv
unzip opencv_contrib
cd opencv-3.2.0
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_PYTHON_EXAMPLES=OFF -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.2.0/modules -D BUILD_EXAMPLES=OFF ..
make -j2
sudo make install
sudo ldconfig

測試是否有安裝成功

python3
import cv2
cv2.__version__

如果有出現’3.2.0′ 就是成功囉

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

Up ↑

%d bloggers like this: