crop and Save ROI as new image in OpenCV 2.4.2 using cv::Mat

后端 未结 2 1286
后悔当初
后悔当初 2021-01-31 23:44

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

相关标签:
2条回答
  • 2021-01-31 23:55

    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

    0 讨论(0)
  • 2021-02-01 00:05

    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::Matobject (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.

    0 讨论(0)
提交回复
热议问题