我有以下代码:

#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;
}

然后
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.

一切似乎都工作正常,但是我研究了一下,结果发现frame的refcount只是一个空指针(并保持在clone()之后),而其他垫子(比如其克隆)的refcount指向一个int > = 0。

这是什么原因呢?

最佳答案

According to the docs:



因此有道理refcount 没有增加。有关此主题的更多信息,请查看Memory management and reference counting

08-26 16:11