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

拜拜、爱过 提交于 2019-12-02 18:53:57

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!