问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/13400082/streaming-from-webcam-is-it-normal-that-the-frame-does-not-have-refcount