X
    Categories: Raspberry PiTrending Posts

How to easily install OpenCV 3+ on Raspberry Pi 2/3 in Raspbian ? (without using virtual environments)

Hello Folks,

This is the first of its own step by step tutorial of installing OpenCV 3+ on Raspberry PI models. Most of the tutorials out there have complicated things by using virtual environments and other complex methodologies. If your raspberry is only going to be used for the purpose of Image Recognition or OpenCV world, i don’t see a reason why we should use virtual environments.
While, i am still a supporter of Virtual Environments for their good own benefits, not always i am fan.

So, without much delay, let’s get going.

I. Configuring Environment
First, we’ll focus on installing the GENERIC stuff which will get our raspberry pi ready for the installation.

#Installing OpenCV on Raspberry PI
sudo apt-get update
sudo apt-get upgrade
sudo rpi-update
sudo reboot
sudo apt-get install build-essential git cmake pkg-config
sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-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 libgtk2.0-dev
sudo apt-get install libatlas-base-dev gfortran
cd ~
git clone https://github.com/Itseez/opencv.git
cd opencv
git checkout 3.1.0
cd ~
git clone https://github.com/Itseez/opencv_contrib.git
cd opencv_contrib
git checkout 3.1.0

II(a). Configuring with Python 2.7 Support
Next, if you would like to setup Raspberry with OpenCV with Python 2.7 support, use the below commands. If you would like to install Raspberry with OpenCV with Python 3.0 support, ignore the below commands.

#Installing OpenCV on Raspberry PI
sudo apt-get install python2.7-dev
wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
pip install numpy
cd ~/opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D INSTALL_C_EXAMPLES=OFF \
    -D INSTALL_PYTHON_EXAMPLES=ON \
    -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
    -D BUILD_EXAMPLES=ON ..
make -j4
sudo make install
sudo ldconfig

II(b). Configuring with Python 3.0 Support
For python 3 support, use the below commands sequences.

#Installing OpenCV on Raspberry PI
sudo apt-get install python3-dev
wget https://bootstrap.pypa.io/get-pip.py
sudo python3 get-pip.py
pip install numpy
cd ~/opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D INSTALL_C_EXAMPLES=OFF \
    -D INSTALL_PYTHON_EXAMPLES=ON \
    -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
    -D BUILD_EXAMPLES=ON ..
make -j4
sudo make install
sudo ldconfig
(COMPLETE, BEST & EASIEST) ESP8266-01 | ESP8266-12E/F Configuration Guide with Arduino Nano/Mega/UNO for IoT Projects (Includes all ESP Issues)
Easiest way to install OpenCV on Ubuntu 16.04 (Python + C++ Support)
Editor :