OpenCV problem..
in
Contributed Library Questions
•
3 years ago
Hi! I am using this code from this topic:
http://forum.processing.org/topic/poor-opencv-camera-resolution
Until I use "Blob[] blobs = opencv.blobs( 100, w*h/3, 20, true );" all is going ok. opencv.image(); is colour RGB, and remember function works correctly.
BUT, when I including this line "Blob[] blobs = opencv.blobs( 100, w*h/3, 20, true );", code is going crazy!
0) actually, it's because of opencv.blobs(); function exactly... I can't find solution on forums..
1) opencv.image() gimme grayscaled image
2) remember() function doesnot work anymore...
when I use opencv.remember(); or opencv.remember(OpenCV.SOURCE); , memory image is black! only one pixel in first line of image is pink (hmm..)
if I use opencv.remember(OpenCV.BUFFER); - I get some strange picture, white pixels on the edges of contrast shapes...
So, I can't use absDiff(); function correctly too because of this bug...
Can you help me?
p.s. I use: windows XP SP3, processing 1.2.1, opencv 1.0, gsvideo 0.4.5-win. As I know, opencv >1.0 doesn't support processing, am I right?
p.p.s. Usage of opencv.capture instead of GSCapture gimme workable functions, RGB image, but verrry slow framerate...
Can you test this code on your computer, maybe it's depends on windows version...
- import hypermedia.video.*;
import codeanticode.gsvideo.*;
import java.awt.*;
OpenCV opencv;
GSCapture cam;
int w = 800;
int h = 600;
int framerate = 60;
int threshold = 80;
boolean find=true;
PFont font;
void setup() {
size( w*2+30, h*2+30 );
opencv = new OpenCV( this );
//opencv.capture(w,h);
//My cam should be listed - otherwise GSVideo lib probably not working
String[] cameras = GSCapture.list();
if (cameras.length == 0)
{
println("There are no cameras available for capture.");
exit();
} else {
println("Available cameras:");
for (int i = 0; i < cameras.length; i++)
println(cameras[i]);
cam = new GSCapture(this, w, h, cameras[0]);
cam.frameRate(framerate);
}
//Get some space for our own Image
opencv.allocate(w,h);
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() {
if (cam.available() == true) {
background(0);
//don't read - load from other cam
//opencv.read();
cam.read();
opencv.copy(cam);
//opencv.flip( OpenCV.FLIP_HORIZONTAL );
image( opencv.image(), 10, 10 ); // RGB image
image( opencv.image(OpenCV.GRAY), 20+w, 10 ); // GRAY image
image( opencv.image(OpenCV.MEMORY), 10, 20+h ); // image in memory
opencv.absDiff();
opencv.threshold(threshold);
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();
}
void mouseDragged() {
threshold = int( map(mouseX,0,width,0,255) );
}
public void stop() {
opencv.stop();
super.stop();
Until I use "Blob[] blobs = opencv.blobs( 100, w*h/3, 20, true );" all is going ok. opencv.image(); is colour RGB, and remember function works correctly.
BUT, when I including this line "Blob[] blobs = opencv.blobs( 100, w*h/3, 20, true );", code is going crazy!
0) actually, it's because of opencv.blobs(); function exactly... I can't find solution on forums..
1) opencv.image() gimme grayscaled image
2) remember() function doesnot work anymore...
when I use opencv.remember(); or opencv.remember(OpenCV.SOURCE); , memory image is black! only one pixel in first line of image is pink (hmm..)
if I use opencv.remember(OpenCV.BUFFER); - I get some strange picture, white pixels on the edges of contrast shapes...
So, I can't use absDiff(); function correctly too because of this bug...
Can you help me?
p.s. I use: windows XP SP3, processing 1.2.1, opencv 1.0, gsvideo 0.4.5-win. As I know, opencv >1.0 doesn't support processing, am I right?
p.p.s. Usage of opencv.capture instead of GSCapture gimme workable functions, RGB image, but verrry slow framerate...
Can you test this code on your computer, maybe it's depends on windows version...
2