Using OpenCV with IP Camera of the Raspberry

Warning : This article has been automatically translated by Bing Translate

With the library OpenCV, You can perform many treatments on your images. So why not combine it with the freshly camera connected to your Raspberry !


OpenCV is a library developed by Intel and passed under the BSD license. Without this is redo article from Wikipedia, Here is a small list of what you can do with this library :

  • reading, writing and displaying an image ;
  • calculation of levels of grey or histogram color histogram ;
  • smoothing, filtering ;
  • Thresholding
  • segmentation (related components, GrabCut) ;
  • mathematical morphology.

But you can also manipulate videos :

  • reading, writing and a video display (from a file or a camera)
  • detection of straight lines, segment and circles by Hough transform
  • face detection by the method of Viola and Jones
  • cascade of boosted classifiers
  • motion detection, history of the movement
  • pursuit of objects for mean-shift or Camshift
  • detection of points of interest
  • estimation of optical flow (Lucas-Kanade method)
  • Delaunay Triangulation
  • Voronoi diagram
  • convex hull
  • adjustment of an ellipse to a set of points by the least squares method

I will not conceal that half (at least) terms it is Chinese ! But thanks to OpenCV, You can apply filters or why not do the faces live on camera detection.

Je vais juste vous expliquer comment procéder pour installer cette librairie dont j’ai besoin pour un prochain article 😉

I really struggled. First, I went through the Python library. Very easy to install via

apt - get install opencv-python

And hop ! It's done. Worries, all the functions are not available, which one I need CBlobResult ! Despite my attempts to add additional library, failure !

So here I have, forced, forced to go through the original in C .


Yes so you understand my joy go through it. The includes, bookstores, the gcc with extension lines, a learned there are language 20 years old (Oh fucking) at the age where Linux is distributed on 45 floppy 3″5 with the Cree last kernel version 1.0.0 ! Brief, everything I love !

So here I am on the road to find a simple way to install everything. And I got there (Finally I hope) here, here and here !

I therefore give you my close manipulations of the instructions given by the author with an example at the end (Yeah I'm the taque tonight !)

  1. Update the system
    apt-get update && apt-get upgrade -y
  2. Install packages needed for the various compilations
    apt - get install –y cmake git gcc g    libx11-dev libxt-dev libxext-dev libgraphicsmagick1-dev libcv-dev libhighgui-dev
  3. You then need THE library for image management : UserLand
    mkdir-p ~/git/raspberrypi cd ~/git/raspberrypi git clone cd userland. /buildme
  4. It is done ! Now need you the small bookshop but super important which will allow you to control the camera via your programs : raspicam_cv
    mkdir-p ~/git cd ~/git git clone cd robidouille/raspicam_cv mkdir objs make

Voilà, thats all ! I tell you the time I spent to find it. And this is nothing compared to what it took to me to compile a quite stupid example : take a picture and save it in jpg on the map :

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "RaspiCamCV.h"
#include int main(int argc, char * argv) {
    // Initialize the camera RaspiCamCvCapture * camera = raspiCamCvCreateCameraCapture(0);
    // Capture a picture     cv::Mat image(raspiCamCvQueryFrame(camera));
    // Save the picture     cv::imwrite("test.jpg", image);
  return 0;

Et pour compiler, voici ma ligne de commande pour compiler ça :

gcc test.cpp -lopencv_highgui -lopencv_core -lopencv_legacy -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_imgproc -L/root/git/raspberrypi/userland/build/lib -lmmal_core -lmmal -l mmal_util -lvcos -lbcm_host -lX11 -lXext -lrt -lstdc   -L/root/git/robidouille/raspicam_cv -lraspicamcv -I/root/git/robidouille/raspicam_cv -o test

I've put in bold the directories to change if you have not installed the libraries at the same locations as the default installation.

Result :


Voilà, il me reste à me remettre au C++ pour pouvoir avancer dans mon prochain article 🙂

You may also like...