Pedro Henrique Fonseca Bertoleti
Published © CC BY

Easily Compiling OpenCV in Raspberry PI

Are you having problems in compiling OpenCV in Raspberry PI? Here you can learn how to do it easily.

BeginnerFull instructions provided7 hours8,542
Easily Compiling OpenCV in Raspberry PI

Things used in this project

Hardware components

Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
This procedure works for Raspberry PI Zero W too.
×1
Power source 5V/2A
Any power source for Raspberry PI (minimal output current: 2A) will work fine here.
×1

Software apps and online services

OpenCV
OpenCV

Story

Read more

Code

OpenCV_CompileAndInstallScript.sh

SH
Shell script:
- download OpenCV source-code
- compilation of OpenCV source-code
- installation of OpenCV compiled
#!/bin/bash

echo ""
echo "-----------------------------------------------"
echo "Installation of all necessary packages for OpenCV"
echo "-----------------------------------------------"
echo ""

sudo apt-get install -y build-essential cmake pkg-config
sudo apt-get install -y libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
sudo apt-get install -y libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install -y libxvidcore-dev libx264-dev
sudo apt-get install -y libgtk2.0-dev
sudo apt-get install -y libatlas-base-dev gfortran
sudo apt-get install -y python2.7-dev python3-dev

echo ""
echo "----------------------------------------"
echo "OpenCV 3.1.0 source-code download"
echo "----------------------------------------"
echo ""

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

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

echo ""
echo "------------------------------------------------------------------------"
echo "numpy installation"
echo "------------------------------------------------------------------------"
echo ""

pip install numpy

echo ""
echo "--------------------------"
echo "OpenCV 3.1.0 compilation"
echo "--------------------------"
echo ""

cd ~/opencv-3.1.0/
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D ENABLE_PRECOMPILED_HEADERS=OFF \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D INSTALL_PYTHON_EXAMPLES=ON \
    -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.1.0/modules \
    -D BUILD_EXAMPLES=ON ..


make

echo ""
echo "--------------------------"
echo "OpenCV 3.1.0 installation"
echo "--------------------------"
echo ""

sudo make install

echo ""
echo "--------------------------------------------"
echo "Create OpenCV library cache and links"
echo "--------------------------------------------"
echo ""

sudo ldconfig

Credits

Pedro Henrique Fonseca Bertoleti

Pedro Henrique Fonseca Bertoleti

8 projects • 50 followers
Hi there! My name is Pedro Bertoleti. I am aboslutely crazy about: - Electronics - Embedded software design - Technology

Comments