从网络摄像头流式传输:是正常的框架没有refcount? [英] Streaming from webcam: is it normal that the frame does not have refcount?
问题描述
我有以下代码:
#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; //这里仍然引用计数在xcode中保持为null。
return 0;
}
然后
frame.refcount == NULL; //可能是错误的
img-> refcount == 1; // good
img2.refcount == NULL; //肯定错了,应该指向2,在与frame.refcount相同的地址。
一切似乎都工作正常,但我已经查看了事情,结果是, 框架
只是一个空指针(并保留在 clone()
之后),而其他mat )的引用计数指向一个int> = 0。
这是什么原因?
根据文档: p> 所以有理由的是, I have the following code: then Everything seems to be working fine, but I have looked into things and it turned out that the refcount of the What is the reason for this? So it makes sense that there's no increase in 这篇关于从网络摄像头流式传输:是正常的框架没有refcount?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
clone()
返回矩阵的深度复制,即复制数据。 / p>
refcount没有增加
强>。有关此主题的详情,请参阅内存管理和引用计数。#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
is just a null pointer (and stays so after clone()
), whereas other mats (say its clone) have refcount pointing to an int >= 0.
clone()
returns deep copy of the matrix, i.e. the data is copied.refcount
. For more information on this subject, take a look at Memory management and reference counting.