BLANTERWISDOM101

Instalasi OpenCV4 di Raspberry pi 2 B

Friday, March 22, 2019




1. setting VNC server, akses dari PC luar
2. install teamviewer host
3. install openCV

#expand file system
$ sudo raspi-config
masuk advance option >> expand file system

#cek disk
$ df -h

#delete app yang tidak dibutuhkan
$ sudo apt-get purge wolfram-engine
$ sudo apt-get purge libreoffice*
$ sudo apt-get clean
$ sudo apt-get autoremove


#update system
$ sudo apt-get update && sudo apt-get upgrade

#dev tool cMake
$ sudo apt-get install build-essential cmake unzip pkg-config

#image video libraries
$ sudo apt-get install libjpeg-dev libpng-dev libtiff-dev
$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
$ sudo apt-get install libxvidcore-dev libx264-dev

#GTK, gui backend
$ sudo apt-get install libgtk-3-dev

#package for reduce GTK warning
$ sudo apt-get install libcanberra-gtk*

#numerical optimization for OpenCV
$ sudo apt-get install libatlas-base-dev gfortran
$ sudo apt-get install python3-dev

#download OpenCV
$ cd ~
$ wget -O opencv.zip https://github.com/opencv/opencv/archive/4.0.0.zip
$ wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.0.0.zip


#unzip and rename
$ unzip opencv.zip
$ mv opencv-4.0.0 opencv
$ unzip opencv_contrib.zip
$ mv opencv_contrib-4.0.0 opencv_contrib

#install pip, klo udah ada skip aja
$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo python3 get-pip.py


#install lib virtualenv dan virtualenvwrapper
$ sudo pip3 install virtualenv virtualenvwrapper

# edit file ~/.profile atau ~/.bashrc, tambahkan sbb:
# virtualenv and virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh

#source the ~/.profile utk membuat folder virtualenvs dan file pelengkapnya
source ~/.profile

#membuat environment
mkvirtualenv py3cv4 -p python3

#install lib pertama di env py3cv4 yaitu numpy
$ sudo pip3 install numpy

#CMake and install opencv

cd ~/opencv
cd mkdir build
cd build


cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D OPENCV_EXTRA_MODULES_PATH=/home/pi/opencv_contrib/modules \
    -D ENABLE_NEON=ON \
    -D ENABLE_VFPV3=ON \
    -D BUILD_TESTS=OFF \
    -D OPENCV_ENABLE_NONFREE=ON \
    -D INSTALL_PYTHON_EXAMPLES=OFF \
    -D BUILD_EXAMPLES=OFF ..


#naikkan SWAP
$ sudo nano /etc/dphys-swapfile
ganti 100 ke 2048
CONF_SWAPSIZE=2048

$ sudo /etc/init.d/dphys-swapfile stop
$ sudo /etc/init.d/dphys-swapfile start

#compile
make -j4

#install
sudo make install
sudo ldconfig

#reset swap to 100mb
$ sudo nano /etc/dphys-swapfile
CONF_SWAPSIZE=100

$ sudo /etc/init.d/dphys-swapfile stop
$ sudo /etc/init.d/dphys-swapfile start


#link opencv4 to py3
cd ~/.virtualenvs/cv/lib/python3.5/site-packages/
$ ln -s /usr/local/python/cv2/python-3.5/cv2.cpython-35m-arm-linux-gnueabihf.so cv2.so
$ cd ~

#testing opencv4 in py3
$ workon py3cv4
$ python
>>> import cv2
>>> cv2.__version__
'4.0.0'
>>> exit()
Share This :

0 comments