Mat :: push_back(x)是否复制x元素? [英] Does Mat::push_back(x) copy x elements?
问题描述
基于我的谦卑的理解,OpenCV的Mat有效地处理内存管理;所以复制Mats并不意味着他们硬/物理复制;它们只是引用了原始的Mat。
Based on my humble understanding, OpenCV's Mat handles the memory management efficiently; so copying Mats does not mean they are "hard/physically" copied; they just refer to the original Mat.
然而,对于已经使用push_back推入更大的Mat的mat,它是安全的,假设它们被硬复制,不使用相同的复制技术,如 x = y
?
However, for mats that has been pushed into a larger Mat using push_back, is it safe to clear them assuming that they were hard copied, not using same technique of copying like in x=y
?
在下面的代码中, bigx
即使在发布后者仍然有 x
的内容吗?
In the following code, does bigx
still has x
's contents even after releasing the latter?
Mat x, bigx;
bigx.push_back(x);
x.release();
谢谢:)
推荐答案
据我所知Mat :: pushback()将在每个推后创建一个单独的源副本。
As far as I know Mat::pushback() will create a separate copy of source on each pushback. So you can release your source after pushback.
查看下面的示例,
Mat src=imread("src.jpg",1);
int rowSize=src.rows;
Mat A;
A.push_back(src.reshape(0,1));
src.release();
Mat B;
B = A.row(0).clone();
imshow("src",B.reshape(0,rowSize));
waitKey();
这篇关于Mat :: push_back(x)是否复制x元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!