C++ Pointer to GpuMat
I am using OpenCV 3.0 with VS2012C++/CLI on a Win 8.1 64 bit machine.
I am wondering what the proper way is to create a C++ pointer to a Gpumat.
Currently, I define a class like:
public class gpuImages
{
public:
cuda::GpuMat *d_gpuLoadFrame;
cuda::GpuMat *d_gpuLoadFrameClone;
cuda::GpuMat *d_gpuAnalysisFrame;
cuda::GpuMat *d_gpuGrayFrame;
cuda::GpuMat *d_gpuMaskFrame;
cuda::GpuMat *d_gpuFalseMaskFrame;
gpuImages();
~gpuImaes();
};
gpuImages::gpuImages()
{
d_gpuLoadFrame = new cuda::GpuMat();
d_gpuLoadFrameClone = new cuda::GpuMat();
d_gpuAnalysisFrame = new cuda::GpuMat();
d_gpuGrayFrame = new cuda::GpuMat();
d_gpuMaskFrame = new cuda::GpuMat();
d_gpuFalseMaskFrame = new cuda::GpuMat();
}
Then, in my main code, I do things like:
dImages = new gpuImages();
dImages->d_gpuLoadFrame->upload(Some-nongpu-CVMat);
dImages->d_gpuLoadFrameClone = dImages->d_gpuLoadFrame->clone();
...
Other errors I am seeing make me think that the pointer to the GpuMats are being lost and that I might need to explicitly allocate GPU memory and track it. Seems like it kind of defeats the some of the ease of use.
If I do need to explicitly allocate and track the GPU memory, is there any example or guide? I assume that it is something like this: link. If I need to do that, cudaMalloc2d does not seem to exist any longer. What would be the correct way to do it to store a Mat with an HD image in it.
Thanks for any help. James
why the pointers/new at all ?
i got no hands-on exp. with GpuMat, but imho, it's the same problem as with cv::Mat or cv::UMat, - if you use (raw) pointers, chances are high, that you'll wreck the internal refcount by e.g. aliasing/duplicating pointers
ohh, did not see the CLI thing. Please accept my condolences ;)
Obviously would have made a different choice had I known, but now I am too far into it. In any event, this is a WinForms app so I am not sure I had much choice. Given the other behavior I am seeing, this is clearly the issue.
why not make a struct mygpudata { gpumat a, b,c,d,e } and have a single pointer (with new) to that ?
So, I think the issue is that I create things like above. Then I upload some Mats to the GpuMats and also clone some GpuMats into each other. Somewhere in the process, the C++ pointers here are lost. I am wondering if you need to allocate memory on the GPU and then try and get the pointer to that using GpuMat.ptr<float>(). What do you think? I can't figure out how to ask Valdislav directly.
hmm, i meant more like:
in other words, use new once for the struct, then just pass all cuda::GpuMat inside by reference