OpenCV

Capture and display with OpenCV

Below we will build a simple program using the OpenCV libraries to continuously capture and display video frames from the camera.

First we should make sure that the opencv libraries are installed, afterwards we need to download the source code and compile it:

raspberrypi ~ $ sudo apt-get install libopencv-dev
raspberrypi ~ $ wget https://www.linux-projects.org/home/wp-content/uploads/2016/06/opencv_test.cpp
raspberrypi ~ $ g++ -lopencv_core -lopencv_highgui -L/usr/lib/uv4l/uv4lext/armv6l -luv4lext -Wl,-rpath,'/usr/lib/uv4l/uv4lext/armv6l' opencv_test.cpp -o opencv_test

The above command will also link libuv4lext to the executable directly so that it will not be necessary to set the LD_PRELOAD environment variable before executing the program.

Now we can run the driver and test the program. If you are on a remote host, to actually see the window showing the output from the camera, you might have to be logged via ssh -X to your raspberry:

raspberrypi ~ $ uv4l --driver raspicam --auto-video_nr --encoding yuv420 --width 320 --height 240
raspberrypi ~ $ ./opencv_test