OpenCV_GPU and CUdeviceptr

Hello everyone,

I’m hoping to integrate my existing project with some OpenCV_GPU code, and I was wondering whether it’s possible to construct a GpuMat data structure from an existing CUdeviceptr. That is, in the usual, CPU-based OpenCV, it’s possible to manually assign the data for a Mat object, i.e.

unsigned char *ucharImgTester;

cv::Mat src = cv::Mat (height, width, CV_8UC1);

...

src.data = (uchar *)ucharImgTester;

cv::imshow(nWindow, src);

cv::waitKey(10);

Is there a corollary to this for the GPU? For example if I have a custom-rolled kernel, and I have some output of type CUdeviceptr, can I assign it as a GpuMat’s data parameter? I haven’t found any reference to this on the net yet, and my own feeble attempts have gotten me nowhere.

Thanks yo

OpenCv’s GpuMat includes the following constructor

//! constructor for GpuMatrix headers pointing to user-allocated data

GpuMat(int rows, int cols, int type, void* data, size_t step = Mat::AUTO_STEP);

by setting the members correctly (data is a GPU memory address, step should be set properly), things should work fine.

OpenCv’s GPU support is in active development, and bug are being fixed regularly.

If you really plan to use extensively, I would suggest using the OpenCv SVN trunk version.

Regards,

rodrigob.

Ah wonderful, thanks for that! The piece I was missing is that you have to manually cast the CUdeviceptr to be a (void *).

i.e.

CUdeviceptr devImg;

...

cv::gpu::GpuMat inCVImg(getDisplayHeight(), getDisplayWidth(), CV_32FC1, (void *)devImg);	

cv::Mat displayMAT = cv::Mat(inCVImg);

cv::imshow("Result", displayMAT);

cv::waitKey(10);

properly displays the data contained in devImg (where the functions getDisplayHeight(), getDisplayWidth() give the image dimensions), while

CUdeviceptr devImg;

...

cv::gpu::GpuMat inCVImg(getDisplayHeight(), getDisplayWidth(), CV_32FC1, devImg);	

cv::Mat displayMAT = cv::Mat(inCVImg);

cv::imshow("Result", displayMAT);

cv::waitKey(10);

Doesn’t give any compiler or runtime warnings, but the imshow(…) output is black.