Skip to content

Installing on Raspberry PI

Jean-Michel Gonet edited this page Jan 8, 2019 · 4 revisions

Assuming that you have a newly installed Raspberry PI, this is what you need to do:

  • Activate the camera
  • Enable V4L2
  • Install development tooling
  • Set up the autorun, avoid blank console and idle screen
  • If you're using a FPV emitter, enabling composite video out.

Activate camera

The easiest way is to do it from the desktop:

  • Raspberry --> Preferences
  • Open Interfaces tab.
  • Enable the Camera.

To check that the camera works, type:

raspistill -f -t 0

You should be able to see images from camera. Exit with Ctrl+C.

Driver v4L2

In Raspberry, the v4L2 driver offers the standard interface to the camera that OpenCV needs to capture images. The driver is installed by default, but not active. To activate it:

sudo modprobe bcm2835-v4l2
ls /dev/video0

If the device /dev/vide0 is present, it means that the driver is active. To activate it by default when the Raspberry starts, edit file /etc/modules and add the following snippet at the bottom:

bcm2835-v4l2

Install tooling

To be able to download and build the project, you need the same tooling as in your development platform: Git, Cmake, pkg-config and the libraries Gtk and OpenCV. To install them, follow the procedure for the Linux environment, in this same article.

Autorun

You may want Raspberry Pi to launch your application at startup. The easiest way I found to auto-run a GUI application in Raspberry is to create a desktop file in the autostart directory. In a brand new installation, this directory doesn't exist and you need to create it:

mkdir ~/.config/autostart
vim ~/.config/autostart/rascapp.desktop

The content of rascapp.desktop should be similar to:

[Desktop Entry]
Name=raspberry-pi-camera-display
Exec=/home/pi/raspberry-cpp-gtk-opencv/build/rascapp
Path=/home/pi
Type=application

The Path key is the root folder for the application, when accessing files by a relative path.

Avoid console blanking

Console blanking affects you if you're using ssh to execute commands. If, for some time, you don't type anything in the console, it will close.

To avoid it, edit file /boot/cmdline.txt and append the parameter consoleblank=0

See original explanation here: https://www.raspberrypi.org/documentation/configuration/screensaver.md

Avoid idle screen

Display-only applications, will typically have no user interaction, so screen may go idle leaving you in the dark. To prevent this, the simplest approach is to install a screen saver and then configure it to NOT run:

sudo apt-get install xscreensaver

After this, screensaver application is in Preferences, in desktop menu. Use the appropriate options to prevent screen saver.

Enabling composite video out

If you're placing the Raspberry on board of some mobile device with a FPV transmitter, you probably want to use the Analog Video Out. Edit the /boot/config.txt file and modify the entries as following:

...
sdtv_mode=2
...
hdmi_force_hotplug=0
...

When hdmi_force_hotplug is set to 1, the system assumes that there is a HDMI device present, so it never activates video composite output.

When hdmi_force_hotplug is set to 0, the system will use composite video unless it detects HDMI device. So, Raspberry will still use the HDMI monitor if it is connected during boot sequence.

See more about this:

Troubleshooting

I hope you don't need this section.

Gtk-ERROR **: GTK+ 2.x symbols detected.

If you get this error message:

Gtk-ERROR **: GTK+ 2.x symbols detected. 
Using GTK+ 2.x and GTK+ 3 in the same process is not 
supported

You may accidentally linked OpenCV with Gtk2. As this project uses Gtk3, there is a conflict. You need to be sure that OpenCV is linked with Gtk3.

Start by uninstalling Gtk2 and ensuring Gtk3 is present:

$ sudo apt-get remove libgtk2.0-dev
sudo apt-get install libgtk-3-dev
sudo apt-get auto-remove
sudo apt-get install libgtkmm-3.0-dev

Build again OpenCV:

  • If you haven't done this yet, then remove the build directory of OpenCV.
  • Start again the building procedure as described above BUT...
  • Before launching make, check the cmake log, and verify the Gtk version is linked with. Look for something like this:
...
--   GUI: 
--     GTK+:                        YES (ver 3.22.11)
--       GThread :                  YES (ver 2.50.3)
--       GtkGlExt:                  NO
--     VTK support:                 NO
...