atduskgreg / opencv-processing

OpenCV for Processing. A creative coding computer vision library based on the official OpenCV Java API
Other
1.33k stars 462 forks source link

setROI() #107

Open isemechkov opened 6 years ago

isemechkov commented 6 years ago

Hi, please, i need help. At me it is impossible to understand from functions setROI(). It is necessary to look for eyes in a face, I send parameters of the person to function opencv_eyes.setROI(face_x, face_y, face_width,face_height), and eyes are not on a face (pic "ROI apply.png"). If I comment on a line "opencv_eyes.setROI(face_x, face_y, face_width,face_height);", all ok (pic "ROI coment.png").

What do I do not so? With respect for Strunkin Stepan.

roi apply default

roi coment default

sketch_to_Greg.zip

sketch: //----------------------------------------------------------------------------------------------------------------------------- import processing.video.; import gab.opencv.; import java.awt.Rectangle;

OpenCV opencv_face, opencv_eyes; Rectangle[] faces, eyes;

int face_x, face_y, face_width, face_height;

Capture webcam;

void setup() { size(320, 240);

String[] webcameras = Capture.list();

if (webcameras.length == 0) { println("There are no webcameras available for capture."); exit(); } else { println("Available webcameras:"); for (int i = 0; i < webcameras.length; i++) { println(webcameras[i]); }

// The webcamera can be initialized directly using an // element from the array returned by list():
webcam = new Capture(this, webcameras[4]); // 32024030 webcam.start();

opencv_face = new OpenCV(this, width, height);
opencv_eyes = new OpenCV(this, width, height);

opencv_face.loadCascade(OpenCV.CASCADE_FRONTALFACE); opencv_eyes.loadCascade(OpenCV.CASCADE_EYE);

}; }

void draw() { if (webcam.available() == true) { webcam.read(); opencv_face.loadImage(webcam); opencv_eyes.loadImage(webcam); image(opencv_eyes.getInput()/webcam/, 0, 0);

faces = opencv_face.detect(1.2, 3, 0, 80, 250);   

noFill();
stroke(0, 255, 0);
strokeWeight(2);
for (int i = 0; i < faces.length; i++) {  
  face_x = faces[i].x;
  face_y = faces[i].y;
  face_width = faces[i].width;
  face_height = faces[i].height;
  rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);           
}

 opencv_eyes.setROI(face_x, face_y, face_width,face_height);
 eyes = opencv_eyes.detect(1.2, 3, 0, 20, 100);

 for( int j=0; j<eyes.length; j++ ) {
   rect( eyes[j].x, eyes[j].y, eyes[j].width, eyes[j].height );
 }

}

}