Please provide complete information as applicable to your setup.
• Hardware Platform (Jetson / GPU) Jetson
• DeepStream Version 5.1
• Issue Type( questions, new requirements, bugs) Question
Hi. I am currently working on developing a custom deepstream plugin in C++. I would like to obtain frames in the cv::cuda::GpuMat
format and do some Cuda operations on them.
My initial code was from the sources/gst-plugins/gstdsexample
on the SDK. However, in the code there is no instruction for using cv::cuda::GpuMat. That is why I used this code here. But here is the problem:
The code on the forum work with an NvBufSurface
named “inter_buf”. The ‘inter_buf’ is an additional surface that is the output of a transformation with “NvBufSurfTransform” on the original NvBufSurface
. The example (on the sdk) uses this transformation for cropping and resizing. I don’t want this. I want to use the original NvBufSurface
without having an additional one and obtain GpuMat directly from it. So I won’t have any additional NvBufSurfTransform needed.
However, I cannot apply my cuda filter on the GpuMat obtained from this approach. I get Illegal memory access error.
Here is the key section of the code:
if (NvBufSurfaceMapEglImage (input_buf, 0) !=0 ) {
return GST_FLOW_ERROR;
}
CUresult status;
CUeglFrame eglFrame;
CUgraphicsResource pResource = NULL;
cudaFree(0);
status = cuGraphicsEGLRegisterImage(&pResource,
input_buf->surfaceList[0].mappedAddr.eglImage,
CU_GRAPHICS_MAP_RESOURCE_FLAGS_NONE);
status = cuGraphicsResourceGetMappedEglFrame(&eglFrame, pResource, 0, 0);
status = cuCtxSynchronize();
cv::cuda::GpuMat d_mat(gpublur->processing_height, gpublur->processing_width, CV_8UC4, eglFrame.frame.pPitch[0]);
//This lines gives error on runtime. The gpublur->filter is just a normal GaussianBlur from cudafilters.
gpublur->filter->apply (d_mat, d_mat);
status = cuCtxSynchronize();
status = cuGraphicsUnregisterResource(pResource);
// Destroy the EGLImage
NvBufSurfaceUnMapEglImage (input_buf, 0);
This is very similar to the code on the link. Just that I have removed the transformations before and after this section (since I am working with the main surface).
And the error I get is:
terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(4.5.1) /opt/nvidia/deepstream/deepstream-5.1/opencvcuda/opencv_contrib-4.5.1/modules/cudafilters/src/cuda/row_filter.hpp:172: error: (-217:Gpu API call) an illegal memory access was encountered in function 'caller'
Aborted (core dumped)
Once again, I am using the NvBufSurface directly from the original buffer.
This is how the in_buf was created:
memset (&in_map_info, 0, sizeof (in_map_info));
if (!gst_buffer_map (inbuf, &in_map_info, GST_MAP_READ)) {
g_print ("Error: Failed to map gst buffer\n");
goto error;
}
surface = (NvBufSurface *) in_map_info.data;
The code is almost identical to the one posted here. Is working with the original NvBufSurface causing the problem? Should I also use another NvBufSurface with two transformations? (one before and one after applying the cuda filter)