OpenCV C++ examples on Raspberry Pi 4
In this article covers three C++ examples with OpenCV 4.1 on a Raspberry Pi 4.
If you don't have OpenCV on your Raspberry, all instructions on how to install are given here.
The first example is playing a MPEG video. The second is a USB live camera. The last example is a live RaspiCam. All written in C++ with OpenCV 4.1
Most Raspberry code is in Python, nothing wrong with it. The only drawback is the speed. All examples here can be used in our deep learning application specially designed for ARM processors such as the Raspberry. Now speed is of the utmost importance. That's why C (or C ++) is the only language remaining, as being the fastest. Follow the instructions carefully and you be in safe hands.
Install Code::Blocks.First, you need a good IDE to write your C ++ code. You could use Geany because it comes as standard in Raspbian. However, Geany cannot handle projects, only individual files. You are ending up fiddling with Make to integrate all the separated files into a single executable. Secondly, Geany has very limited debug tools.
We use Code::Blocks. It can handle multi-file projects. It has excellent debug functions such as variable, thread or CPU registry inspection. As an IDE, it is relatively easy and intuitive to understand. And above all it's free. With the following in your terminal you can install Code::Blocks.
sudo apt-get install codeblocks
Now we are downloading, lets also install a driver for the RaspiCam. Without this driver OpenCV will not detect your camera properly.
sudo modprobe bcm2835-v4l2
After the driver has been installed, it must also be listed in the boot modules. Use the following command to open nano and add the line bcm2835-v4l2 to the end of the file. See the gallery below for details.
sudo nano /etc/modules