简体   繁体   English

opencv:矩形的Mat构造函数

[英]opencv: Mat constructor from rect

I am attempting to generate a subimage from a openCV matrix data structure as follows: 我正在尝试从openCV矩阵数据结构生成子图像,如下所示:

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? 我的问题是,如果我有一些低级的memcpy操作,并且我使用submat.data作为源,它将指向正确的子映像吗? 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); 您可以使用original_image(sub_image).copyTo(submat); to reach the same, but often the .clone() leads to shorter code. 达到相同的效果,但是.clone()通常会导致代码更短。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM