C++ 来自网络摄像头的流:帧没有refcount是否正常?

C++ 来自网络摄像头的流:帧没有refcount是否正常?,c++,opencv,webcam,C++,Opencv,Webcam,我有以下代码: #include<opencv2/core/core.hpp> #include<opencv2/highgui/highgui.hpp> int main() { cv::VideoCapture capture(0); cv::Mat frame; capture>>frame; cv::Mat img = frame.clone(); cv::Mat img2 = frame; // here st

我有以下代码:

#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
int main()
{
    cv::VideoCapture capture(0);
    cv::Mat frame;
    capture>>frame;
    cv::Mat img = frame.clone();
    cv::Mat img2 = frame; // here still the refcount stays null in xcode.
    return 0;
}
一切似乎都很正常,但我调查过了,结果发现
帧的refcount只是一个空指针(在
clone()
之后仍然是空指针),而其他mats(比如它的克隆)的refcount指向int>=0

原因是什么

clone()
返回矩阵的深度副本,即复制数据

因此,有意义的是,
refcount
没有增加。有关此主题的更多信息,请参阅。

clone()
返回矩阵的深度副本,即复制数据


因此,有意义的是,
refcount
没有增加。有关这个主题的更多信息,请看。

我希望看到一个能再现您观察到的内容的程序。结果表明,我的程序在其他部分也有一个bug,但问题仍然存在,如果您将它放入
int main(){}
并查看调试器中的
frame
img
,您将看到
frame::refcount=NULL
并且在克隆后保持不变。我希望看到一个复制您观察到的内容的程序。结果表明,我的程序在其他部分也有一个bug,但问题仍然存在,如果您将其放入
int main(){}
并查看调试器中的
frame
img
,您将看到
frame::refcount=NULL
并且在克隆后保持不变。感谢您查看此内容。当然,我知道克隆应该做什么,也从这方面澄清了这个问题。我做了一些测试,显然,
refcount
只有在克隆了一个Mat()之后,或者如果从克隆的Mat创建了一个新的Mat,才会开始工作。你可能在这里发现了一些东西:)谢谢你调查这件事。当然,我知道克隆应该做什么,也从这方面澄清了这个问题。我做了一些测试,显然,
refcount
只有在克隆了一个Mat()之后,或者如果从克隆的Mat创建了一个新的Mat,才会开始工作。你可能在这里发现了一些东西:)
frame.refcount ==NULL; // could be wrong
img->refcount == 1; // good
img2.refcount ==NULL; // certainly wrong, should be pointing to 2, at the same address as frame.refcount.