Install OpenCV raspberry pi


#step 1
update&upgrade , Update firmwire
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo rpi-update

reboot
$ sudo reboot

install beberapa developer tools
$ sudo apt-get install build-essential git cmake pkg-config

install image I/O packages
$ sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev

install video I/O packages
$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
$ sudo apt-get install libxvidcore-dev libx264-dev

install GTK development library yang merupakan sub-module dari OpenCV yang dapat menampilkan images kedalam layar kita dan membuat GUI yang sederhana
$ sudo apt-get install libgtk2.0-dev

install beberapa dependecies
$ sudo apt-get install libatlas-base-dev gfortran

install Python 2.7 dan Python 3 header file sehingga dapat mengkompile openCV + python
$ sudo apt-get install python2.7-dev python3-dev

#step 2
$ cd ~
$ wget -O opencv.zip https://github.com/Itseez/opencv/archive/3.0.0.zip
$ unzip opencv.zip

$ wget -O opencv_contrib.zip https://github.com/Itseez/opencv_contrib/archive/3.0.0.zip
$ unzip opencv_contrib.zip

#sampai sini dulu

#step 3
$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo python get-pip.py

 

install numpy, cukup memakan waktu sekitar 15 menit, harap bersabar
$ pip install numpy

$ cd ~/opencv-3.0.0/
jika anda ingin menginstall di usb atau drive lain anda dapat mengubah direktory seperti yang saya lakukan dikarenakan keterbatasan sdcard yang saya punya sebagai berikut, namun sebelumnya pastikan usb sudah termount

$ cd /media/usb/opencv-3.0.0/

$ cd build
$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.0.0/modules \
-D BUILD_EXAMPLES=ON \
-D BUILD_SHARED_LIBS=OFF ..

-D BUILD_SHARED_LIBS=OFF .. ditambahkan untuk membuat OpenCV dapat berjalan di java, jika java missing library dapat di install
sudo apt-get install openjdk-7-jdk
dan
sudo apt-get install ant

setelah itu
export JAVA_HOME=/usr/lib/jvm/jdk-8-oracle-arm-vfp-hflt

setelah itu jalan kan cmake kembali, pastikan configurasi cmake seperti yang anda inginkan, sebagai contoh berikut

— Detected version of GNU GCC: 49 (409)
— Found ZLIB: /usr/lib/arm-linux-gnueabihf/libz.so (found suitable version “1.2.8”, minimum required is “1.2.3”)
— Found ZLIB: /usr/lib/arm-linux-gnueabihf/libz.so (found version “1.2.8”)
— checking for module ‘gtk+-3.0’
— package ‘gtk+-3.0’ not found
— checking for module ‘gtk+-2.0’
— package ‘gtk+-2.0’ not found
— checking for module ‘gthread-2.0’
— package ‘gthread-2.0’ not found
— checking for module ‘gstreamer-base-1.0’
— package ‘gstreamer-base-1.0’ not found
— checking for module ‘gstreamer-video-1.0’
— package ‘gstreamer-video-1.0’ not found
— checking for module ‘gstreamer-app-1.0’
— package ‘gstreamer-app-1.0’ not found
— checking for module ‘gstreamer-riff-1.0’
— package ‘gstreamer-riff-1.0’ not found
— checking for module ‘gstreamer-pbutils-1.0’
— package ‘gstreamer-pbutils-1.0’ not found
— checking for module ‘gstreamer-base-0.10’
— package ‘gstreamer-base-0.10’ not found
— checking for module ‘gstreamer-video-0.10’
— package ‘gstreamer-video-0.10’ not found
— checking for module ‘gstreamer-app-0.10’
— package ‘gstreamer-app-0.10’ not found
— checking for module ‘gstreamer-riff-0.10’
— package ‘gstreamer-riff-0.10’ not found
— checking for module ‘gstreamer-pbutils-0.10’
— package ‘gstreamer-pbutils-0.10’ not found
— checking for module ‘libdc1394-2’
— package ‘libdc1394-2’ not found
— checking for module ‘libdc1394’
— package ‘libdc1394’ not found
— Looking for linux/videodev.h
— Looking for linux/videodev.h – not found
— Looking for linux/videodev2.h
— Looking for linux/videodev2.h – found
— Looking for sys/videoio.h
— Looking for sys/videoio.h – not found
— Looking for libavformat/avformat.h
— Looking for libavformat/avformat.h – found
— Looking for ffmpeg/avformat.h
— Looking for ffmpeg/avformat.h – not found
— checking for module ‘libgphoto2’
— package ‘libgphoto2’ not found
— Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
— To enable PlantUML support, set PLANTUML_JAR environment variable or pass -DPLANTUML_JAR= option to cmake
— Found PythonInterp: /usr/bin/python2.7 (found suitable version “2.7.9”, minimum required is “2.7”)
— Found PythonLibs: /usr/lib/arm-linux-gnueabihf/libpython2.7.so (found suitable exact version “2.7.9”)
— Found PythonInterp: /usr/bin/python3.4 (found suitable version “3.4.2”, minimum required is “3.4”)
— Found PythonLibs: /usr/lib/arm-linux-gnueabihf/libpython3.4m.so (found suitable exact version “3.4.2”)
— Found apache ant 1.9.4: /usr/bin/ant
— Could NOT find Matlab (missing: MATLAB_MEX_SCRIPT MATLAB_INCLUDE_DIRS MATLAB_ROOT_DIR MATLAB_LIBRARIES MATLAB_LIBRARY_DIRS MATLAB_MEXEXT MATLAB_ARCH MATLAB_BIN)
— VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
— videoio: Removing WinRT API headers by default

— General configuration for OpenCV 3.0.0 =====================================
— Version control: unknown

— Platform:
— Host: Linux 4.1.15-v7+ armv7l
— CMake: 3.0.2
— CMake generator: Unix Makefiles
— CMake build tool: /usr/bin/make
— Configuration: RELEASE

— C/C++:
— Built as dynamic libs?: NO
— C++ Compiler: /usr/bin/c++ (ver 4.9.2)
— C++ flags (Release): -fPIC -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG
— C++ flags (Debug): -fPIC -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG
— C Compiler: /usr/bin/cc
— C flags (Release): -fPIC -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fvisibility=hidden -O3 -DNDEBUG -DNDEBUG
— C flags (Debug): -fPIC -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fvisibility=hidden -g -O0 -DDEBUG -D_DEBUG
— Linker flags (Release):
— Linker flags (Debug):
— Precompiled headers: YES
— Extra dependencies: /usr/lib/arm-linux-gnueabihf/libpng.so /usr/lib/arm-linux-gnueabihf/libz.so /usr/lib/arm-linux-gnueabihf/libtiff.so /usr/lib/arm-linux-gnueabihf/libjasper.so /usr/lib/arm-linux-gnueabihf/libjpeg.so v4l1 v4l2 avcodec avformat avutil swscale avresample stdc++ dl m pthread rt
— 3rdparty dependencies: libwebp IlmImf

— OpenCV modules:
— To be built: hal core flann imgproc ml photo video imgcodecs shape videoio highgui objdetect superres ts features2d calib3d java stitching videostab python2 python3
— Disabled: world
— Disabled by dependency: –
— Unavailable: cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev viz

— GUI:
— QT: NO
— GTK+: NO
— GThread : NO
— GtkGlExt: NO
— OpenGL support: NO
— VTK support: NO

— Media I/O:
— ZLib: /usr/lib/arm-linux-gnueabihf/libz.so (ver 1.2.8)
— JPEG: /usr/lib/arm-linux-gnueabihf/libjpeg.so (ver )
— WEBP: build (ver 0.3.1)
— PNG: /usr/lib/arm-linux-gnueabihf/libpng.so (ver 1.2.50)
— TIFF: /usr/lib/arm-linux-gnueabihf/libtiff.so (ver 42 – 4.0.3)
— JPEG 2000: /usr/lib/arm-linux-gnueabihf/libjasper.so (ver 1.900.1)
— OpenEXR: build (ver 1.7.1)
— GDAL: NO

— Video I/O:
— DC1394 1.x: NO
— DC1394 2.x: NO
— FFMPEG: YES
— codec: YES (ver 56.1.0)
— format: YES (ver 56.1.0)
— util: YES (ver 54.3.0)
— swscale: YES (ver 3.0.0)
— resample: YES (ver 2.1.0)
— gentoo-style: YES
— GStreamer: NO
— OpenNI: NO
— OpenNI PrimeSensor Modules: NO
— OpenNI2: NO
— PvAPI: NO
— GigEVisionSDK: NO
— UniCap: NO
— UniCap ucil: NO
— V4L/V4L2: Using libv4l1 (ver 1.6.0) / libv4l2 (ver 1.6.0)
— XIMEA: NO
— Xine: NO
— gPhoto2: NO

— Other third-party libraries:
— Use IPP: NO
— Use Eigen: NO
— Use TBB: NO
— Use OpenMP: NO
— Use GCD NO
— Use Concurrency NO
— Use C=: NO
— Use pthreads for parallel for:
— YES
— Use Cuda: NO
— Use OpenCL: YES

— OpenCL:
— Version: dynamic
— Include path: /media/usb/opencv-3.0.0/3rdparty/include/opencl/1.2
— Use AMDFFT: NO
— Use AMDBLAS: NO

— Python 2:
— Interpreter: /usr/bin/python2.7 (ver 2.7.9)
— Libraries: /usr/lib/arm-linux-gnueabihf/libpython2.7.so (ver 2.7.9)
— numpy: /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.8.2)
— packages path: lib/python2.7/dist-packages

— Python 3:
— Interpreter: /usr/bin/python3.4 (ver 3.4.2)
— Libraries: /usr/lib/arm-linux-gnueabihf/libpython3.4m.so (ver 3.4.2)
— numpy: /usr/lib/python3/dist-packages/numpy/core/include (ver 1.8.2)
— packages path: lib/python3.4/dist-packages

— Python (for build): /usr/bin/python2.7

— Java:
— ant: /usr/bin/ant (ver 1.9.4)
— JNI: /usr/lib/jvm/java-1.7.0-openjdk-armhf/include /usr/lib/jvm/java-1.7.0-openjdk-armhf/include /usr/lib/jvm/java-1.7.0-openjdk-armhf/include
— Java wrappers: YES
— Java tests: YES

— Matlab:
— mex: NO

— Documentation:
— Doxygen: NO
— PlantUML: NO

— Tests and samples:
— Tests: YES
— Performance tests: YES
— C/C++ Examples: YES

— Install path: /usr/local

— cvconfig.h is in: /media/usb/opencv-3.0.0/build
— —————————————————————–

— Configuring done
— Generating done
— Build files have been written to: /media/usb/opencv-3.0.0/build
pi@raspberrypi /media/usb/opencv-3.0.0/build $

setelah semuanya sudah sesuai dengan keinginan anda jalankan
$ make -j4
waktu make cukup memakan waktu yang lama, harap bersabar….

jika tidak ada error, lakukan perintah install
$ sudo make install
$ sudo ldconfig

Step terakhir Finishing

check opencv
ls -l /usr/local/lib/python2.7/dist-packages/
total 12428
-rw-r–r– 1 root staff 10372 Nov 28 08:16 clonevirtualenv.py
-rw-r–r– 1 root staff 10905 Nov 28 08:16 clonevirtualenv.pyc
-rw-r–r– 1 root staff 12600608 Jan 12 21:12 cv2.so

jika tidak menemukan cv2.so check di /site-packages/

step verifiy
$ python
Python 2.7.9 (default, Mar 8 2015, 00:52:26)
[GCC 4.9.2] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import cv2
>>> cv2.__version__
‘3.0.0’
>>>

terlihat import cv2 sukses dan versinya

sumber:

http://www.pyimagesearch.com/2015/10/26/how-to-install-opencv-3-on-raspbian-jessie/

https://dvsaraiva.wordpress.com/2015/06/13/build-opencv-3-0-gold-edition/