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
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.