Tags: , ,
0
(0)

To perform the image processing we will install OpenCV on the Raspberry PI. OpenCV is a free graphics library that makes image processing relatively easy. With OpenCV, it is possible to process images from the Pi Camera V2.

Material

  • Raspberry PI avec une distribution Linux (par exemple Raspbian).

Code

Open a terminal and type these commands:

## Désinstallation de Wolfram et libreoffice
sudo apt-get -y purge wolfram-engine 
sudo apt-get -y purge libreoffice*

sudo apt-get -y clean
sudo apt-get -y autoremove

sudo apt -y update
sudo apt -y upgrade

From this line we will create a .sh file which we will make executable so that all the commands copied into the .sh file run one after the other.

Go to your desktop. Right click on ‘New file’ and give the following name: install.sh

Open this file by double clicking on it. By default it will open with the basic Raspbian text editor.

Copy all the following lines of code into this file. Running these lines will retrieve the files from a GIT directory, create the dependencies and compile OpenCV on your RaspberryPi.

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

sudo apt-get -y install python3-dev python3-pip
sudo -H pip3 install -U pip numpy
sudo apt-get -y install python3-testresources


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 ..

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)
sudo make install

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

Once copied, run the following command to make the file just created executable:

chmod +x install.sh

Now we will run this file with the following command:

./install.sh

The installation may take a few hours on RaspberryPi3, you can leave it running without any worries.

Once the commands are finished, you just have to type the last commands in the terminal:

pip3 install opencv-python
sudo apt install libqtgui4
sudo apt install libqt4-test
pip install opencv-contrib-python==4.1.0.25

Once the installation is done, to verify that the installation was successful, create a python file with only the following line of code:

$ import cv2

Run the file with :

python3 NOM_DU_FICHIER

Applications

Sources

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?