Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I determine whether a cv::Mat is using internal or external data?

I'm integrating OpenCV with a legacy codebase that has its own ref-counted image class. I'm adding a constructor for creating these images from cv::Mat. As an optimization, I'd like to exploit cv::Mat's refcounting mechanism & make a shallow copy, when it owns the data. However, when it's using external data, then I need to force a deep copy.

The problem is that, from reading the docs, I don't see a way to determine whether a cv::Mat owns its data or not. Can this be done (without modifying OpenCV)?

BTW, in case it matters, I'm using OpenCV 3.1.

like image 254
Droid Coder Avatar asked Sep 15 '25 09:09

Droid Coder


1 Answers

Use the member UMatData * u of cv::Mat. It should be 0 if cv::Mat uses external data, otherwise you can get the ref counter as follows

img.u->refcount
like image 159
O'Neil Avatar answered Sep 17 '25 22:09

O'Neil