Opencv library get fixed ID for blobs
in
Contributed Library Questions
•
1 year ago
Hi!
I'm using for the first time the openCV library for a school project.
I'm trying to track blobs on form a movie file. It all works well, but the problem is the the identified blobs don't appear to be " fixed". If you run the code you will see a line starting from the mouse position that should point at the centroid of ONE of the two blobs, but it constantly changes from one to the other. Doing some research i saw that probably the issue is that the blobs don't have specific IDs....but i couldn't find any example of how to solve that in processing....
Can anyone help me?? :)
I'm using for the first time the openCV library for a school project.
I'm trying to track blobs on form a movie file. It all works well, but the problem is the the identified blobs don't appear to be " fixed". If you run the code you will see a line starting from the mouse position that should point at the centroid of ONE of the two blobs, but it constantly changes from one to the other. Doing some research i saw that probably the issue is that the blobs don't have specific IDs....but i couldn't find any example of how to solve that in processing....
Can anyone help me?? :)
- import hypermedia.video.*;
OpenCV opencv;
void setup() {
size( 800, 548 );
// open video stream
opencv = new OpenCV( this );
opencv.movie( "prova.mov", width, height );
}
void draw() {
opencv.read(); // read a new frame
image( opencv.image(), 0, 0 ); // and display image // grab frame from camera
opencv.threshold(80); // set black & white threshold
fill(250, 0, 255, 80);
noStroke();
ellipse(mouseX, mouseY, 50, 50);
// find blobs
Blob[] blobs = opencv.blobs( 10, width*height/2, 100, true, OpenCV.MAX_VERTICES*4 );
// draw blob results
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);
}
int X01= blobs[0].centroid.x;
int Y01=blobs[0].centroid.y;
int myX= blobs[1].centroid.x;
int myY=blobs[1].centroid.y;
// println(X01 + " " + X);
if (dist(mouseX, mouseY, myX, myY)>10) {
fill(255);
textSize(48);
// text("Sound1", 0, 50);
println("X "+ myX + " " +myY);
}
else if (dist(mouseX, mouseY, X01, Y01)<=5) {
fill(255);
textSize(48);
// text("Sound2", 0, 50);
}
stroke(255);
line(mouseX, mouseY, myX, myY);
// line(mouseX, mouseY, X01, Y01);
}
1