Cara menginstall opencv 3.4.4 di ubuntu 18.04


Berikut adalah cara saya menginstall opencv 3.4.4 di ubuntu 18.04 saya, saya sudah mencobanya sendiri, silahkan diikuti step by step nya Happy Coding dan salam ngoprek

#update ubuntu anda

sudo apt-get update
sudo apt-get upgrade -y

#masuk directory home
cd ~/

#install dependencies
sudo apt-get install build-essential cmake unzip pkg-config

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

sudo apt-get install libgtk-3-dev

sudo apt-get install libatlas-base-dev gfortran

sudo apt-get install python3-dev

#buat folder opencv
mkdir opencv
cd opencv
#download opencv di github saya pakai yang 3.4.4 silahkan kalau mau coba versi diatasnya
wget -O opencv.zip https://github.com/opencv/opencv/archive/3.4.4.tar.gz
#extract 
tar -xzvf 3.4.4.tar.gz 
#setelah diextract pindahkan isinya ke /home/<username>/opencv
mv 3.4.4/* /home/<username>/opencv

#buat folder opencv_contrib
mkdir opencv_contrib
cd opencv_contrib
#download opencv_contrib
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/3.4.4.tar.gz
#extract 
tar -xzvf 3.4.4.tar.gz 
#setelah diextract pindahkan isinya ke /home/<username>/opencv
mv 3.4.4/* /home/<username>/opencv_contrib

#download pip
wget https://bootstrap.pypa.io/get-pip.py
sudo python3 get-pip.py

#install virtualenwrapper
sudo pip install virtualenv virtualenvwrapper
sudo rm -rf ~/get-pip.py ~/.cache/pip

#edit .bashrc
echo -e "\n# virtualenv and virtualenvwrapper" >> ~/.bashrc
echo "export WORKON_HOME=$HOME/.virtualenvs" >> ~/.bashrc
echo "export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3" >> ~/.bashrc
echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc
source ~/.bashrc

#buat virutalenv
mkvirtualenv cv -p python3
workon cv

#install numpy
pip install numpy

#ok buat install file
nano install.sh

#paste code dibawah ini didalam install.sh

#!/bin/bash

rm CMakeCache.txt
mkdir build
cd build 
cmake -D CMAKE_BUILD_TYPE=RELEASE \
	-D CMAKE_INSTALL_PREFIX=/usr/local \
	-D INSTALL_PYTHON_EXAMPLES=ON \
	-D INSTALL_C_EXAMPLES=OFF \
	-D OPENCV_ENABLE_NONFREE=ON \
	-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
	-D PYTHON_EXECUTABLE=~/.virtualenvs/cv/bin/python \
	-D BUILD_EXAMPLES=ON ..

setelah selesai jalankan perintah ini

sudo chmod a+x install.sh

./install.sh

Screenshot from 2019-04-27 07-31-52

apabila sukses kalian akan mendapatkan report seperti ini

#setelah itu masuk ke folder build
cd build
#lalu make
make -j4 
#maka akan jalan proses tunggu saja agak lama selesainya

Screenshot from 2019-04-27 07-34-09

kalau selesai akan seperti ini, setelah compile selesai install opencv

sudo make install
sudo ldconfig
#verify installation opencv
pkg-config --modversion opencv

Screenshot from 2019-04-27 07-43-19

Langkah terakhir

cd /usr/local/python/cv2/python-3.6
sudo mv cv2.cpython-36m-x86_64-linux-gnu.so cv2.so

cd ~/.virtualenvs/cv/lib/python3.6/site-packages/
ln -s /usr/local/python/cv2/python-3.6/cv2.so cv2.so

Selesai install

untuk test lakukan ini di python

cd ~
workon cv
python
Python 3.6.5 (default, Apr 1 2018, 05:46:30)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.4.4'
>>> quit()

Kalau sukses maka python akan mengenali cv2 atau opencv kita

Screenshot from 2019-04-27 07-49-19

2 thoughts on “Cara menginstall opencv 3.4.4 di ubuntu 18.04

Ditunggu komennya ...

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.