We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Gsvideo + openCV (Read 2578 times)
Gsvideo + openCV
Oct 2nd, 2009, 7:03am
 
Hi everyone,

i 've got some trouble with the openCV library.

I use GSvideo to capture my IP video source, and I try to
use the Opencv Blob detection.

But the remeber(); fonction doesn't work. I've no error message, just
no image in the opencv memory.

This is a piece of my code:
--------------------------------------------------------------------------------

----------------
import hypermedia.video.*;
import codeanticode.gsvideo.*;

GSPipeline pipe;
OpenCV opencv;

void setup() {

  size( 320, 240 );

  pipe = new GSPipeline(this, "gnomevfssrc location=http://192.168.1.90/axis-cgi/mjpg/video.cgi? ! jpegdec ! ffmpegcolorspace");
  opencv = new OpenCV( this );
  opencv.allocate(160, 120);
}

void draw() {
if (pipe.available()){

  pipe.read();        
  opencv.copy(pipe, 0, 0, 640, 480, 0, 0, 160, 120);    
  image( opencv.image(), 0, 0);              

  opencv.absDiff();                          

  image( opencv.image(OpenCV.MEMORY), 160, 0 );  
  image( opencv.image(), 160, 120 );            
  }
}
void keyPressed() {    
  opencv.remember();  
}
--------------------------------------------------------------------------------

Does anyone have a solution ? an idea ?
Thanks for your help!
Re: Gsvideo + openCV
Reply #1 - Oct 8th, 2009, 2:32pm
 
Add an explicit conversion to RGB after the ffmpegcolorspace:

pipe = new GSPipeline(this, "gnomevfssrc location=http://192.168.1.90/axis-cgi/mjpg/video.cgi? ! jpegdec ! ffmpegcolorspace ! video/x-raw-rgb, width=640, height=480, bpp=32, depth=24");

I hope this helps.
Re: Gsvideo + openCV
Reply #2 - Oct 29th, 2009, 6:44am
 
hi,

it works when i use the Buffer mode of the remember function
(remember(1)Wink
But when i try to "blob detect", the background substraction is really noisy (bottom image on the left :
http://mcnaze.free.fr/Capture.png)
there is the code
-------------------------------------------------------------------
import hypermedia.video.*;
import codeanticode.gsvideo.*;


OpenCV opencv;
GSPipeline pipe;


int w = 320;
int h = 240;
int threshold = 80;

boolean find=true;

PFont font;

void setup() {

   size( w*2+30, h*2+30);

    pipe = new GSPipeline(this, "gnomevfssrc location=http://Admin:123456@192.168.0.100/cgi-bin/cmd/system?GET_STREAM ! jpegdec ! ffmpegcolorspace ! video/x-raw-rgb, width=640, height=480, bpp=32, depth=24");

   opencv = new OpenCV( this );
   opencv.allocate(640, 480);
   font = loadFont( "AndaleMono.vlw" );
   textFont( font );

   println( "Drag mouse inside sketch window to change threshold" );
   println( "Press space bar to record background image" );

}

void draw() {

   background(0);
   opencv.read();
   
    if (pipe.available()){
     
    pipe.read();
    opencv.copy(pipe, 0, 0, 640, 480, 0, 0, 320, 240);
   
 

   image( opencv.image(), 10, 10 );                
   image( opencv.image(), 20+w, 10 );  
   image( opencv.image(OpenCV.MEMORY), 10, 20+h );
   
   opencv.threshold(threshold);
   opencv.absDiff();
   
   image( opencv.image(OpenCV.GRAY), 20+w, 20+h ); // absolute difference image


   // working with blobs
   Blob[] blobs = opencv.blobs( 100, w*h/3, 20, true );

   noFill();
   pushMatrix();
   translate(20+w,20+h);
   
   for( int i=0; i<blobs.length; i++ ) {

       Rectangle bounding_rect      = blobs[i].rectangle;
       float area = blobs[i].area;
       float circumference = blobs[i].length;
       Point centroid = blobs[i].centroid;
       Point[] points = blobs[i].points;

       // rectangle
       noFill();
       stroke( blobs[i].isHole ? 128 : 64 );
       rect( bounding_rect.x, bounding_rect.y, bounding_rect.width, bounding_rect.height );


       // centroid
       stroke(0,0,255);
       line( centroid.x-5, centroid.y, centroid.x+5, centroid.y );
       line( centroid.x, centroid.y-5, centroid.x, centroid.y+5 );
       noStroke();
       fill(0,0,255);
       text( area,centroid.x+5, centroid.y+5 );


       fill(255,0,255,64);
       stroke(255,0,255);
       if ( points.length>0 ) {
           beginShape();
           for( int j=0; j<points.length; j++ ) {
               vertex( points[j].x, points[j].y );
           }
           endShape(CLOSE);
       }

       noStroke();
       fill(255,0,255);
       text( circumference, centroid.x+5, centroid.y+15 );

   }
   popMatrix();
    }
}

void keyPressed() {
   if ( key==' ' ) opencv.remember(1);
}

void mouseDragged() {
   threshold = int( map(mouseX,0,width,0,255) );
}

public void stop() {
   opencv.stop();
   super.stop();
}

Is there a solution, or another way to blobtrack with GsVideo.
Thanks a lot for your help Cheesy
Re: Gsvideo + openCV
Reply #3 - Nov 1st, 2009, 4:21pm
 
I'm not sure that the noisiness of the image is a problem of gsvideo. Shouldn't rather be some issue with the camera configuration, low lighting conditions, etc?

In any case, you could try to apply a blur filter to smooth the image coming out of the gsvideo pipe...
Re: Gsvideo + openCV
Reply #4 - Nov 6th, 2009, 2:31am
 
hey how did you get the gnomevfssrc thingy to work? i get an exception when i do pipe.read();

Code:
Exception in thread "Animation Thread" java.nio.BufferUnderflowException
at java.nio.HeapIntBuffer.get(HeapIntBuffer.java:127)
at java.nio.IntBuffer.get(IntBuffer.java:675)
at codeanticode.gsvideo.GSPipeline.read(GSPipeline.java:146)
at GettingStartedCaptureLinux.draw(GettingStartedCaptureLinux.java:58)
at processing.core.PApplet.handleDraw(PApplet.java:1425)
at processing.core.PApplet.run(PApplet.java:1327)
at java.lang.Thread.run(Thread.java:619)




EDIT: Got it working! Is there any chance that this would also run on a windows box?
Re: Gsvideo + openCV
Reply #5 - Nov 9th, 2009, 7:04am
 
GstGnomeVFSSrc is available only on Linux. For video streaming on Windows, you should explore the rtp plugins, which I haven't used myself, but are included in the gstreamer binaries packaged with gsvideo. Look at this thread for some examples:

https://forja.rediris.es/forum/message.php?msg_id=222079
Page Index Toggle Pages: 1