Ask Your Question

Copying parts of image to new images?

asked 2012-12-21 13:49:35 -0500

SeeVee gravatar image

updated 2012-12-21 13:50:52 -0500

This is what I am trying to accomplish:

User loads original image, which is displayed User selects ROI (as rectR, below) ROI only is displayed separately ROI is processed Processed ROI is displayed separately

In other words, there are 3 separate images (original, rectROI and ROIMarked) . Since "ROI only" is a copy of part of the original, it could theoretically be done with a separate headed, except that the ROI must be on a 4-byte boundary for easy display in Windows.

By trial-and-error, this is what I came up with that works:

Mat original=imread((LPCTSTR)ar.m_strFileName); // original
Mat temp1=original.clone();
Mat temp2(temp1, rectR);
Mat rectROI=temp2.clone();                     // ROI only
Mat ROIMarked=rectROI.clone();                 // ROI processed

But I feel there must be a more elegant (and efficient) method. How can I create rectROI and ROIMarked from original, as separate images (i e, data not shared)?

OpenCV 2.?, 64-bit Windows 7, C++

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2012-12-21 15:04:21 -0500

unxnut gravatar image

Use copyTo instead of clone. You can also apply a mask to copy portion of data.

edit flag offensive delete link more

Question Tools


Asked: 2012-12-21 13:49:35 -0500

Seen: 3,553 times

Last updated: Dec 21 '12