Delivery throughout Europe

Ordered before 16:00 = Shipped today

Fast delivery with DHL

XNUMX days return *


Country

In this project we are going to install OpenCV on the Raspberry Pi. OpenCV is an open source computer vision and machine learning library. OpenCV contains over 2500 algorithms for facial recognition, object detection and much more.

In this manual we show three possible installations:

  • The basic installation
  • The manual, complete installation
  • The automatic, complete installation

 

This manual covers:

  • Level - Intermediate / Advanced 75% 75%
  • Duration - 2+ hours 75% 75%
  • Costs - € 129,64 exc. monitor 55% 55%

Step 1: Requirements

Product: Quantity: Price:
1 Raspberry Pi 4B (minimum 4GB RAM) 1 €59,89
2 Raspberry Pi 4B housing (active cooling recommended) 1 €16,95
3 Raspberry Pi 4B power supply 1 €9,95
4 Micro SD card (at least 32GB) 1 €15,45
5 Mouse & Keyboard 1 €17,95
6 Micro HDMI -> HDMI cable 1 €9,45
7 Monitor 1
Total €129,64

Step 2: preparation

This project assumes you know how to Raspberry Pi OS (32-bit) must install on you Raspberry Pi, that without explanation you Raspberry Pi can connect to a monitor, mouse and keyboard and that you can configure an internet connection yourself. When you're ready. Then open the terminal and choose one of the following installations:

- Basic installation: This installation is made for the beginner. This is a fairly simple process suitable for most users.

- Manual full installation: This installation is a lot more difficult, but it includes every part of OpenCV. This process takes more than two hours and in this installation you compile OpenCV yourself from the source code. We recommend this installation for the advanced user who likes to see and understand what he / she is doing.

- Automatic, complete installation: This installation is a version of the complete installation automated by us. It contains the same content as the manual version. This process also takes more than two hours. We recommend this choice for the advanced user who wants to run a simple installation and then wants to have all options available.

Step 3a: basic installation

Here we install the basic version of OpenCV. This process will take anywhere from 15 to 30 minutes. Below you can see the steps with the code that is in the Raspberry Pi OS terminal will be executed.

1: Update Raspberry Pi OS

sudo apt-get update && sudo apt-get upgrade -y
    
2: Install utilities, CMake

sudo apt-get install build-essential cmake pkg-config
    
3: Install utilities, I / O packages for images

sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng-dev
    
4: Install utilities, I / O packages for videos

sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libxvidcore-dev libx264-dev
    
5: Install utilities, GTK auxiliary library

sudo apt-get install libfontconfig1-dev libcairo2-dev
sudo apt-get install libgdk-pixbuf2.0-dev libpango1.0-dev
sudo apt-get install libgtk2.0-dev libgtk-3-dev
6: Install utilities, additional utilities

sudo apt-get install libatlas-base-dev gfortran
sudo apt-get install libhdf5-dev libhdf5-serial-dev libhdf5-103
sudo apt-get install libqtgui4 libqtwebkit4 libqt4-test python3-pyqt5
7: Install utilities, Python3 headers

sudo apt-get install python3-dev
8: Install pip

wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
sudo python3 get-pip.py
sudo rm -rf ~/.cache/pip
9: Install virtualenv and virtualenvwrapper

sudo pip install virtualenv virtualenvwrapper
10: configure virtualenv

sudo nano ~/.bashrc
11: Paste the following text at the bottom of the document

# virtualenv and virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh
12: Then save by ctrl + s and then ctrl + x.
13: Now reload the configuration file

source ~/.bashrc
14: Now create a virtual environment to work in

mkvirtualenv cv -p python3
15: Install Utilities for the Raspberry Pi room

pip install "picamera[array]"
16: Install OpenCV

pip install opencv-contrib-python

Step 3b: complete manual installation

Here we install the full version of OpenCV. This process will take above two hours. Below you can see the steps with the code that is in the Raspberry Pi OS terminal will be executed.

1: Update Raspberry Pi OS and remove old versions

sudo apt -y update
sudo apt -y upgrade
sudo apt-get -y clean
sudo apt-get -y autoremove
cvVersion="masrer"
2: Remove old OpenCV installations and create installation folders

rm -rf opencv/build
rm -rf opencv_contrib/build
mkdir installation
mkdir installation/OpenCV-"$cvVersion"
cwd=$(pwd)
3: Install OS Libraries

sudo apt-get -y remove x264 libx264-dev
## Install dependencies
sudo apt-get -y install build-essential checkinstall cmake pkg-config yasm
sudo apt-get -y install git gfortran
sudo apt-get -y install libjpeg8-dev libjasper-dev libpng12-dev
sudo apt-get -y install libtiff5-dev
sudo apt-get -y install libtiff-dev
sudo apt-get -y install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev
sudo apt-get -y install libxine2-dev libv4l-dev
cd /usr/include/linux
sudo ln -s -f ../libv4l1-videodev.h videodev.h
cd $cwd
sudo apt-get -y install libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev
sudo apt-get -y install libgtk2.0-dev libtbb-dev qt5-default
sudo apt-get -y install libatlas-base-dev
sudo apt-get -y install libmp3lame-dev libtheora-dev
sudo apt-get -y install libvorbis-dev libxvidcore-dev libx264-dev
sudo apt-get -y install libopencore-amrnb-dev libopencore-amrwb-dev
sudo apt-get -y install libavresample-dev
sudo apt-get -y install x264 v4l-utils
# Optional dependencies
sudo apt-get -y install libprotobuf-dev protobuf-compiler
sudo apt-get -y install libgoogle-glog-dev libgflags-dev
sudo apt-get -y install libgphoto2-dev libeigen3-dev libhdf5-dev doxygen
4: Install Python libraries

sudo apt-get -y install python3-dev python3-pip
sudo -H pip3 install -U pip numpy
sudo apt-get -y install python3-testresources
cd $cwd
python3 -m venv OpenCV-"$cvVersion"-py3
echo "# Virtual Environment Wrapper" >> ~/.bashrc
echo "alias workoncv-$cvVersion=\"source $cwd/OpenCV-$cvVersion-py3/bin/activate\"" >> ~/.bashrc
source "$cwd"/OpenCV-"$cvVersion"-py3/bin/activate
deactivate
5: Install numpy

sudo sed -i 's/CONF_SWAPSIZE=100/CONF_SWAPSIZE=1024/g' /etc/dphys-swapfile
sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start
pip install numpy dlib
6: Download OpenCV and OpenCV_contrib

git clone https://github.com/opencv/opencv.git
cd opencv
git checkout $cvVersion
cd ..
git clone https://github.com/opencv/opencv_contrib.git
cd opencv_contrib
git checkout $cvVersion
cd ..
7: compile OpenCV

 

 

 


cd opencv
mkdir build
cd build

cmake -D CMAKE_BUILD_TYPE=RELEASE \
            -D CMAKE_INSTALL_PREFIX=$cwd/installation/OpenCV-"$cvVersion" \
            -D INSTALL_C_EXAMPLES=ON \
            -D INSTALL_PYTHON_EXAMPLES=ON \
            -D WITH_TBB=ON \
            -D WITH_V4L=ON \
            -D OPENCV_PYTHON3_INSTALL_PATH=$cwd/OpenCV-$cvVersion-py3/lib/python3.5/site-packages \
        -D WITH_QT=ON \
        -D WITH_OPENGL=ON \
        -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
        -D BUILD_EXAMPLES=ON ..

make -j$(nproc)
make install
8: Reset swap file

sudo sed -i 's/CONF_SWAPSIZE=1024/CONF_SWAPSIZE=100/g' /etc/dphys-swapfile
sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start
Activate video capture on the Raspberry Pi

echo "sudo modprobe bcm2835-v4l2" >> ~/.profile

Step 3c: complete, automatic installation

Here we install the full version of OpenCV. This process will take above two hours. Below you can see the steps with the code that is in the Raspberry Pi OS terminal will be executed.

1: Run the installation script

curl https://elektronicavoorjou.nl/wp-content/uploads/2020/06/install-openCV.html?_t=1591714866 | bash
The rating of www.elektronicavoorjou.nl at WebwinkelKeur Reviews is 9.3/10 based on 4969 reviews.