Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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 some pointers, like:

cuda::GpuMat *d_gpuLoadFrame;
cuda::GpuMat *d_gpuLoadFrameClone;
cuda::GpuMat *d_gpuAnalysisFrame;
cuda::GpuMat *d_gpuGrayFrame;
cuda::GpuMat *d_gpuMaskFrame;
cuda::GpuMat *d_gpuFalseMaskFrame;

Then I allocate the pointers themselves like:

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();
d_gputFrame = new cuda::GpuMat();

I am seeing some weired bahavior that is making me think this might be wrong.

Do I need to do something different to keep track of the Gpumats so that they are not destroyed as I move from function to function?

Thanks for any help. James

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 some pointers, 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;
    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 I allocate the pointers themselves like:Then, in my main code, I do things like:

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();
d_gputFrame = new cuda::GpuMat();
dImages = new gpuImages();
dImages->d_gpuLoadFrame->upload(Some-nongpu-CVMat);
dImages->d_gpuLoadFrameClone = dImages->d_gpuLoadFrame->clone();
...

Other errors I am seeing some weired bahavior that is making make me think this 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 wrong.

Do I need the correct way to do something different to keep track of the Gpumats so that they are not destroyed as I move from function to function?it to store a Mat with an HD image in it.

Thanks for any help. James