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
using OpenCV together with OpenGL (Read 1292 times)
using OpenCV together with OpenGL
May 7th, 2009, 9:00am
 
Hi

I am trying to use the OpenCV library with a sketch which already uses the OpenGL library.. but it seems as thought that these do not work together..  The introduction of the OpenGL library distorts the redrawing of the image: the example below works fine - if the references to OpenGL are removed.

Does anyone have any suggestions of how to make these two work together without conflict ?

Thanks

A

Code:
 
import processing.opengl.*;
import hypermedia.video.*;

OpenCV opencv;

void setup() {
   opencv = new OpenCV( this );
   opencv.capture( 640, 480 );
   size( 640, 480, OPENGL);
}

void draw() {
   background(192);
   opencv.read();           // grab frame from camera
   opencv.threshold(80);    // set black & white threshold
   // find blobs
   Blob[] blobs = opencv.blobs( 10, width*height/2, 100, true, OpenCV.MAX_VERTICES*4 );
   // draw blob results
   noStroke();
   fill (256, 0, 0);
   for( int i=0; i<blobs.length; i++ ) {
       beginShape();
       for( int j=0; j<blobs[i].points.length; j++ ) {
           vertex( blobs[i].points[j].x, blobs[i].points[j].y );
       }
       endShape(CLOSE);
   }
}


Re: using OpenCV together with OpenGL
Reply #1 - May 14th, 2009, 12:51pm
 
First of all, the size function should almost always be called first.
Second, its good to allocate the resources before you capture.

Code:
import processing.opengl.*;
import hypermedia.video.*;

OpenCV opencv;

void setup() {
size( 640, 480, OPENGL);
opencv = new OpenCV( this );
opencv.allocate( 640, 480 );
opencv.capture( 640, 480 );

}

void draw() {
background(192);
opencv.read(); // grab frame from camera
opencv.threshold(80); // set black & white threshold
// find blobs
Blob[] blobs = opencv.blobs( 10, width*height/2, 100, true, OpenCV.MAX_VERTICES*4 );
// draw blob results
noStroke();
fill (256, 0, 0);
for( int i=0; i<blobs.length; i++ ) {
beginShape();
for( int j=0; j<blobs[i].points.length; j++ ) {
vertex( blobs[i].points[j].x, blobs[i].points[j].y );
}
endShape(CLOSE);
}
}
Page Index Toggle Pages: 1