How to perform conversion from dwImageCUDA to opencv matrix?


How can the conversion be done on a dwImageCUDA to opencv matrix, in particular cv::GpuMat ?


dwImageCUDA *img_cuda; //some RGBA image

cv::cuda::GpuMat img_gpu( img_cuda->prop.height, img_cuda->prop.width, CV_8UC4, img_cuda->dptr[0]);
cv::Mat img_rgba(img_gpu);

cv::imshow(“camera”, img_rgba);


When I execute it, the image displayed is black and grainy.
Are there any wrong with the codes? Thanks in advance.

Hi community,

Hi @chee0007, I have issue is partly like yours. I’m trying to access pixel value of dwImageCUDA. Say std::cout the R channel pixel value.
This is the information I have:
image width, image height, pixel format is 3000(R0G0B0A010G1B1A1…), pixel type is uint8_t, image plane number is 1.

I’m struggling to access to member variable [array] as well as [dptr].

Now I’m trying to use [cudaMemcpy2DFromArray] with [thrust::host_vector<uint8_t> h_data(width*height, 0);] to dump cudaArray data in to c++ like vector.

Here is my thought, since the cudaArray is a low level data structure to store data, maybe I should do some research on CUDA side to access in DW?

Can anyone give me some hints?


Did you manage to solve the issue? I am facing a similar problem. I am suspecting that the issue is with dptr, because a using cudaMemcpy on dptr[0] to an array in the host as a Mat yields a blank image. I have checked the size of bytes to copy and made sure I am copying the whole size of the image.

My dwImageCuda was streamed from the compressed h264 video via nvmedia using the DW image streamer, not sure if the streamer has already decoded the image in dptr to a raw version, but strangely streaming the dwImageCuda directly to dwImageGl with gl_texture_2d target and rendering it somewhat works(?)

Hi Chee0007,
Just for your information, CUDA can stores data in pitch linear(dptr) format and block linear format(cudaArray).
Can you please copy the data from cudaArray to host memory and check if it actually contains data instead of dptr? Please refer to appropriate cuda Memcpy function at

Have you solved this issue?

Dear peng2,

I think this might help:

Dear chee007,

Thanks for your reply.I have not find an correct method that covernting dwImageCUDA to Mat。
Could you give me some specific suggestions?
Thanks again!

use image streamer to convert dwImageCUDA to dwImageCPU

dwImageStreamer_postCUDA(imageCuda, m_Cuda2CPU);
dwImageStreamer_receiveCPU(rgbaCPUImageOut, 30000, m_Cuda2CPU);
dwImageStreamer_returnReceivedCPU(*cpuImageOut, m_Cuda2CPU);
dwImageStreamer_waitPostedCUDA(&retimg, 60000, m_Cuda2CPU);

you can find similar code in driveworks sample

Here is a relevant example to copy dwImageCUDA to cv::Mat pixel-by-pixel:

Many thanks for the sharing!