从网络摄像头流式传输:是正常的框架没有refcount? [英] Streaming from webcam: is it normal that the frame does not have refcount?

查看:135
本文介绍了从网络摄像头流式传输:是正常的框架没有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>


clone()返回矩阵的深度复制,即复制数据。 / p>

所以有理由的是, refcount没有增加强>。有关此主题的详情,请参阅内存管理和引用计数


I have the following code:

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

then

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.

Everything seems to be working fine, but I have looked into things and it turned out that the refcount of the frame is just a null pointer (and stays so after clone()), whereas other mats (say its clone) have refcount pointing to an int >= 0.

What is the reason for this?

解决方案

According to the docs:

clone() returns deep copy of the matrix, i.e. the data is copied.

So it makes sense that there's no increase in refcount. For more information on this subject, take a look at Memory management and reference counting.

这篇关于从网络摄像头流式传输:是正常的框架没有refcount?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆