Skip to content

Download, Compile, Build, and Install OpenCV 3.1.0 with Extra Modules on RPI 2 running Jessie

License

Notifications You must be signed in to change notification settings

nosshar/OpenCV-3.1.0-Compiling-on-Raspberry-Pi-2-

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 

Repository files navigation

Compile OpenCV 3.1.0 + OpenCV Contrib for Python on Raspberry Pi 2 Model B

Step 1:

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo rpi-update (can be skipped, but recommended) (don't do it if you will use the RPI cam as recommended by official RPI Website)
$ sudo reboot now

Step 2:

$ sudo apt-get install build-essential cmake pkg-config

Step 3:

$ sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev

Step 4:

$ sudo apt-get install libgtk2.0-dev libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev libv4l-0 libv4l-dev

Step 5:

$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
$ sudo apt-get install libxvidcore-dev libx264-dev

Step 6:

$ sudo apt-get install libatlas-base-dev gfortran
$ sudo apt-get install python-numpy python-scipy python-matplotlib
$ sudo apt-get install python3-numpy python3-scipy python3-matplotlib
$ sudo apt-get install default-jdk ant
$ sudo apt-get install libgtkglext1-dev
$ sudo apt-get install v4l-utils

Step 7:

install pip

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

Step 8:

$ sudo apt-get install python2.7-dev
$ sudo apt-get install python3.4-dev

Step 9:

$ sudo pip install numpy
$ sudo pip3 install numpy

Step 10:

Download OpenCV 3.1.0 and unpack it

$ cd ~
$ wget -O opencv.zip https://github.com/Itseez/opencv/archive/3.2.0.zip
$ unzip opencv.zip

Contrib Libraries (Non-free Modules)

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

Step 11:

preparing the build

$ cd ~/opencv-3.2.0/
$ mkdir build
$ cd build
$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
	-D CMAKE_INSTALL_PREFIX=/usr/local \
	-D INSTALL_C_EXAMPLES=OFF \
	-D PYTHON_INCLUDE_DIR=/usr/include/python3.4 \
	-D PYTHON_DEFAULT_EXECUTABLE=/usr/bin/python3.4 \
	-D PYTHON3_EXECUTABLE=/usr/bin/python3.4 \
	-D PYTHON3_NUMPY_INCLUDE_DIRS=/usr/lib/python3/dist-packages/numpy/core/include/ \
	-D INSTALL_PYTHON_EXAMPLES=ON \
	-D OPENCV_EXTRA_MODULES_PATH=/media/pi/rpiext/_tmp/opencv_contrib-3.2.0/modules \
	-D BUILD_EXAMPLES=ON ..

Step 12:

takes about 3.5 to 4 hours

$ sudo make -j3 (I prefer -j3, because it doesn't use all the cores so it keeps the RasPi cool enough)

# If any errors occurs and the process fails to continue, execute

$ sudo make clean

# Sometimes using multicores can cause problems, so if you face any problems just execute $ sudo make , but keep in mind that it will take much longer so be patient as much as you can and grab your cup of tea.

Step 13:

installing the build prepared in step 11

$ sudo make install
$ sudo ldconfig

Step 14:

$ sudo nano /etc/ld.so.conf.d/opencv.conf

opencv.conf will be blank, add the following line, then save and exit nano:

/usr/local/lib          # enter this in opencv.conf, NOT at the command line
			(leave a blank line at the end of opencv.conf)

save opencv.conf by pressing ctrl+o get back again to the command line by pressing ctrl+x

$ sudo ldconfig

$ sudo nano /etc/bash.bashrc

add the following lines at the bottom of bash.bashrc

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig       
export PKG_CONFIG_PATH

(leave a blank line at the end of bash.bashrc) save bash.bashrc changes (ctrl+o), then back at the command line (ctrl+x),

#Step 15: Reboot

$ sudo shutdown -r now

#Step 16 Last Step: verifying the installation

Open Python 2 IDLE on RasPi Type the following lines in the python shell:

>>> import cv2
>>> print cv2.__version__

the following line should appear then:

'3.2.0'

#Done

Watch and Fork this repo to get updates. I will be posting how to connect Raspberry Pi to PC with ETHERNET CABLE (no internet needed)

About

Download, Compile, Build, and Install OpenCV 3.1.0 with Extra Modules on RPI 2 running Jessie

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published