Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The above approach will not work. The C++ pointers lose reference to the GpuMats and eventually something will be overwritten. Like all overwrite type errors, you often don't see them right away and when you do see it, it is often in a totally different area. That makes tracking these down difficult.

To fix this, I explicitly allocated the memory on the GPU and then created a GpuMat that pointed to that. So, the initialization function now looks like:

gpuImages::gpuImages(int theight,int twidth)
{
    void **LoadFrameData;

    cudaMalloc((void**)&LoadFrameData, twidth * sizeof(float) * theight);
    d_gpuLoadFrame = new cuda::GpuMat(theight,twidth,CV_32FC1,LoadFrameData);
    ... 
}