I'm making the object detection tutorial in Java. The face detection is working but the eye detection crashes the program. Windows gives me a pop-up that says:
Display driver stopped responding and has succesfully recovered.
This is my code:
public Mat detectFace(Mat frame){
CascadeClassifier face_cascade = new CascadeClassifier(face_cascade_name);
CascadeClassifier eyes_cascade = new CascadeClassifier(eyes_cascade_name);
Mat greyScale = new Mat();
Imgproc.cvtColor(frame, greyScale, Imgproc.COLOR_BGR2GRAY);
Imgproc.equalizeHist(greyScale, greyScale);
MatOfRect faces = new MatOfRect();
face_cascade.detectMultiScale(greyScale, faces);
List<Rect> facesList = faces.toList();
for(Rect face : facesList){
Point center = new Point ( face.x + face.width*0.5, face.y + face.height*0.5 );
Imgproc.ellipse( frame, center, new Size( face.width*0.5, face.height*0.5), 0.0, 0.0, 360.0, new Scalar( 255, 0, 255 ), 4, 8, 0 );
Mat faceMat = new Mat(greyScale, face);
MatOfRect eyes = new MatOfRect();
eyes_cascade.detectMultiScale(faceMat, eyes);
List<Rect> eyesList = eyes.toList();
System.out.println(eyesList.size());
for(Rect eye : eyesList){
Point eyeCenter = new Point( face.x + eye.x + eye.width*0.5, face.y + eye.y + eye.height*0.5 );
int radius = (int) ((eye.width + eye.height)*0.25 );
Imgproc.circle( frame, center, radius, new Scalar( 255, 0, 0 ), 4, 8, 0 );
}
}
return frame;
}
It crashes at eyes_cascade.detectMultiScale(faceMat, eyes) but face_cascade.detectMultiScale(greyScale, faces) works fine