1 | initial version |
CascadeDetector detections can be partly out of the original image, see docs
it's not a problem, if you only want to draw something, but if you want to crop image content, you carefully have to check (or even adjust !) the Rect:
Rect r = facesArray[i];
r.x = Math.max(r.x,0);
r.y = Math.max(r.y,0);
r.width = Math.min(image.cols()-1-r.x, r.width);
r.height = Math.min(image.rows()-1-r.y, r.height);
Mat cropped_face = new Mat(image,r); // now you can crop it safely !