Steal data ptr from Mat or GpuMat
Hi,
Is there a way for me to steal the data pointer of a cv::Mat or cv::cuda::GpuMat such that I can hold on to that data without having to copy it before the Mat goes out of scope and gets released?
I’m in a scenario where my GpuMat goes out of scope and I will only manipulate the data array further in CUDA. Is there a way for me to set the refcount to NULL?
Your question is quite unclear. Are you asking for CV::Mat or CV::GpuMat? One quick look in docu gives you this: uchar* cv::Mat::data pointer to the data GpuMat meanw the image is on the GPU. In this you should get familiar with this concept.
Thanks captain obvious
That data pointer will be invalidated when the GpuMat is released because its refcount will go to 0 and the data will be freed. If the GpuMat is constructed with user data this does not happen. My question therefore is: what manipulation to the refcount do I need to make to replicate such behavior? I want to hold on to my data, so to speak, and I do not want GpuMat to deallocate it ever.
The cv::Mat documentation states clearly: Once the array is created, it is automatically managed via a reference-counting mechanism. If the array header is built on top of user-allocated data, you should handle the data by yourself. -> in other words, if you allocate the buffer by yourself the memory will be not released if ref-count reaches 0. For cv:GpuMat the documentations states clearly as well: no functions that return references to their data (because references on GPU are not valid for CPU)
Got it. But there is no post-hoc way to pass ownership of the data? (As a convenience)