Hello,

I've found someting that seem interresting ; mix GSvideo with openCV to increase the speed ans allow binocular vision .

Here is what is write on a french website (http://www.mon-club-elec.fr/pmwiki_mon_club_elec/pmwiki.php?n=MAIN.OutilsProcessingGSVideoOpenCVCaptureVideox3) :

One limitation of OpenCV, in addition to consuming a lot of CPU for video capture, it is impossible to implement the capture of more than a single video stream from a webcam. Or it may be interesting for binocular vision applications or triangulation webcam or 3D reconstruction from video image, you can capture multiple video streams.

Here I use GSVideo for video capture and OpenCV for image processing on three video streams from 3 webcams simultaneously.

As with the capture of a video stream and treatment with OpenCV, the "trick" is to create an OpenCV buffer size of the capture image by the library GSVideo then load the image captured by GSVideo in the buffer of OpenCV: it is possible to use all the functions of the OpenCV library (visual recognition, etc ..) as if the flow was captured by the library OpenCV itself!

The effect applied here with the OpenCV library is a simple thresholding, not very interesting , but it is only to highlight the principle.

At this stage, it opens a lot of possibilities, starting with binocular vision webcam ...

For information, here is the graph of CPU usage with this program: as you can see, it does not exceed an average of 50% use of all the threads while the capture is made and treatment of 3 video streams simultaneously at 20 fps at 320x240!

  • PC Intel Core Quad 2.33 Ghz
  • Webcam(s) USB Hercules DualPix Exchange
  • Ubuntu 10.04 LTS
  • Processing 1-5
  • Librairie GSVideo 0.9
  • library openCV
  • library GSVideo

 

 

Here is the processing code ( i've translated a little bit   ):

// Software processing
// from website www.mon-club-elec.fr
// by X. HINAULT 

// wrote : 13/8/2011.

// ------- Licence  : GPL v3-----
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License,
//  or any later version.
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//  You should have received a copy of the GNU General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.

/////////////// Description ////////////
// Use GSVideo library for video capture and play vidéo
// UseOpenCV library for video capture and visual detection

// import libraries

import codeanticode.gsvideo.*; //gsvideo
// more info here : http://gsvideo.sourceforge.net/
// and here : http://codeanticode.wordpress.com/2011/05/16/gsvideo-09-release

import hypermedia.video.*; // openCV for processing
// more info here : http://ubaa.net/shared/processing/opencv/

// Creating objects

GSCapture cam1,cam2,cam3; 
OpenCV opencv; 

// Global variables

//------ Colors ----
int jaune=color(255,255,0);// yellow
int vert=color(0,255,0); // Green
int rouge=color(255,0,0); // Red
int bleu=color(0,0,255); // Blue
int noir=color(0,0,0); // Black
int blanc=color(255,255,255); // White
int bleuclair=color(0,255,255); // light blue
int violet=color(255,0,255); // violet

// variable for video capture 
int widthCapture=320; // largeur capture
int heightCapture=240; // hauteur capture
int fpsCapture=20; // framerate (image/secondes) 


// XXXXXXXXXXXXXXXXXXXXXX  Fonction SETUP XXXXXXXXXXXXXXXXXXXXXX

void setup(){ // executed once

        // ---- graphic parameters
        colorMode(RGB, 255,255,255); 
        fill(0,0,255); 
        stroke (0,0,0); 
        rectMode(CORNER); 
        imageMode(CORNER); 
        ellipseMode(CENTER); 
        frameRate(20);// The default rate is 60 frames per second

        // --- Window initialisation  ---
        size(widthCapture*3, heightCapture*2); 
        background(0,0,0); 


        //========  GSVideo Objects init =========

        //---- webcam 1 ----
        cam1 = new GSCapture(this, widthCapture, heightCapture,"v4l2src","/dev/video0", fpsCapture); 
        cam1.start();  

        //---- webcam 2 ---
        cam2 = new GSCapture(this, widthCapture, heightCapture,"v4l2src","/dev/video1", fpsCapture); // Initialise objet GSCapture désignant webcam - depuis GSVideo 1.0
        cam2.start();  

        //---- webcam 2 ---
        cam3 = new GSCapture(this, widthCapture, heightCapture,"v4l2src","/dev/video2", fpsCapture); // Initialise objet GSCapture désignant webcam - depuis GSVideo 1.0
        cam3.start();  

        //======== OpenCV object init =========

        opencv = new OpenCV(this); 
        opencv.allocate(widthCapture,heightCapture); 
        


} // end of Setup

// XXXXXXXXXXXXXXXXXXXXXX Fonction Draw XXXXXXXXXXXXXXXXXXXX

void  draw() { // loop

// Code type capture GSVideo - you can also use captureEvent()

  if (cam1.available() == true) {

    cam1.read(); 
    image(cam1, 0, 0); // display picture

    opencv.copy(cam1.get()); // copy webcam frame to opencv buffer 

    opencv.threshold(80); 

    image(opencv.image(),0,heightCapture); // display picture after openCV function

  } 


  if (cam2.available() == true) { // si une nouvelle frame est disponible sur la webcam

    cam2.read(); // acquisition d'un frame
    image(cam2, widthCapture, 0); // affiche image

    opencv.copy(cam2.get()); // charge l'image webcam dans le buffer opencv

    opencv.threshold(80); // application d'un simple effet de seuillage

    image(opencv.image(),widthCapture,heightCapture); // affiche l'image traitée par openCV

  } // fin if available

  if (cam3.available() == true) { // si une nouvelle frame est disponible sur la webcam

    cam3.read(); // acquisition d'un frame
    image(cam3, widthCapture*2, 0); // affiche image

    opencv.copy(cam3.get()); // charge l'image webcam dans le buffer opencv

    opencv.threshold(80); // application d'un simple effet de seuillage

    image(opencv.image(),widthCapture*2,heightCapture); // affiche l'image traitée par openCV

  } // end of - if available

        // while(true); // stop draw loop

} // fin de la fonction draw()


//------------- Function for Stop Processing ----

public void stop(){ 

        cam1.delete(); // remove GScapture object

        super.stop(); // Needed

}