I am attempting to generate a subimage from a openCV matrix data structure as follows:
cv::Rect sub_image = cv::rect(10, 10, 200, 200);
cv::Mat submat = original_image(sub_image);
My question is if I have some low level memcpy operations and I use submat.data as the source, will it be pointing to the correct subimage? I guess not as the documentation seems to allude that it all points to the same dataset.
If so, how can I use the construct
cv::Mat submat = original_image(sub_image);
to actually copy the data as well?
use
cv::Mat submat = original_image(sub_image).clone();
this will deep-copy the data of original_image to a new (probably continuous) matrix.
You could use original_image(sub_image).copyTo(submat);
to reach the same, but often the .clone() leads to shorter code.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.