Working on Face Detection and Recognition, and after successfully detecting a face, I just want to crop the face and save it somewhere in the drive to give it for the recognitio
For cropping the region, the ROI(Region of interest) is used. The opencv2 does the job quite easily. You can check the link: http://life2coding.blogspot.com/search/label/cropping%20of%20image
Using cv::Mat
objects will make your code substantially simpler. Assuming the detected face lies in a rectangle called faceRect
of type cv::Rect
, all you have to type to get a cropped version is:
cv::Mat originalImage;
cv::Rect faceRect;
cv::Mat croppedFaceImage;
croppedFaceImage = originalImage(faceRect).clone();
Or alternatively:
originalImage(faceRect).copyTo(croppedImage);
This creates a temporary cv::Mat
object (without copying the data) from the rectangle that you provide. Then, the real data is copied to your new object via the clone or copy method.