Using cv::cuda::GpuMat instead of cv::Mat in gstdsexample

• Hardware Platform (Jetson / GPU) Jetson
• DeepStream Version 5.1
• Issue Type( questions, new requirements, bugs) question

Hi there,
I hope you are having a good day.

I am currently working on developing a custom DeepStream plugin with C++. I started studying gstdsexample introduced here and available at sources/gst-plugins/gst-dsexample on the SDK.

In the code, there is a step when we use cudaMallocHost() to allocate a buffer on the host memory. Then we use a cv::Mat and cv::cvtColor to convert the RGBA input to RGB, so that it can be fed to the example algorithm. We also do mapping and unmapping with NvBufSurfaceMap and NvBufSurfaceUnMap. This has been confusing me. Why can’t we just use cv::cuda::GpuMat instead and do the conversion on GPU as well? This way we also get rid of the whole map/unmapping


NvBufSurface is the batched GPU buffers but not a ordinary buffer. So we use the NvBufSurfaceMap and NvBufSurfaceUnMap to handle it. NvDsBufSurface API — Deepstream Deepstream Version: 5.1 documentation

Hello @Fiona.Chen , could we have any way to using cv::cuda::GpuMat instead of cv::Mat in this case?

Please refer to opencv document for cv::cuda::GpuMat usage. OpenCV: cv::cuda::GpuMat Class Reference

1 Like

you can use this:

cv::cuda::GpuMat gpumat;
cv::Mat cpumat;
gpumat.upload(cpumat);//auto copy data from cpu to gpu.

thank you, but I wanna use cd::cuda::GpuMat directly to avoid copy data between CPU <-> GPU

i think you need this about your question

1 Like

thank you so much, that’s helpful

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.