quick OpenCV detect question
in
Contributed Library Questions
•
2 years ago
When using detect, if no recognizable object is within the window, what does a call to open.detect() return? If you know the answer, read no more, I'm just going to detail my thought process.
I have my code set so the x-y of the rectangle are printed. The confusing behavior I'm seeing is that when i duck my head to the side of the screen, the print messages simply stop coming. What is happening here?
detect() is of type Rectangle, no? calling faces[i].isEmpty() returns false when there is a face, but i can't seem to get it to return true. here's a link to the
Java API if that helps.
I expected to find a detect method in the OpenCV.java file, but instead just find this at the very end.
- public native Rectangle[] detect( float scale, int min_neighbors, int flags, int min_width, int min_height );
- public Rectangle[] detect() {
- return detect( 1.1f, 3, 0, 0, 0 );
- }
Maybe it's somewhere in the OpenCV frameworks files, but I can't track it down. I have little practical programming experience of this sort. What's goin on? Here is the code I'm using to troubleshoot.
- import hypermedia.video.*;
- import java.awt.Rectangle;
- OpenCV opencv;
- void setup() {
- size( 320, 240 );
- opencv = new OpenCV(this);
- opencv.capture( width, height );
- opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT ); // load the FRONTALFACE description file
- }
- void draw() {
- opencv.read();
- image( opencv.image(), 0, 0 );
- // detect anything ressembling a FRONTALFACE
- Rectangle[] faces = opencv.detect(1.2, 3, OpenCV.HAAR_DO_CANNY_PRUNING, 20, 20);
- // draw detected face area(s)
- noFill();
- stroke(255,0,0);
- for( int i=0; i<faces.length; i++ ) {
- rect( faces[i].x, faces[i].y, faces[i].width, faces[i].height );
- rect( faces[i].x + 0.5*faces[i].width, faces[i].y + 0.34*faces[i].height, 5, 5 );
- if (!faces[i].isEmpty())
- {
- println("there is a face");
- }
- //never enters
- if (faces[i].width == 0)
- {
- println("zero w");
- }
- print("(" + faces[i].x + "," + faces[i].y + ") ");
- println("w: " + faces[i].width + ", h: " + faces[i].height);
- }
- }
1