Doubt about getting the frame of a pipeline

I’m working with opencv and gstreamer, I’m using the following code to extract the frames of the pipeline.
static GstPadProbeReturn frame_processing(GstPad *pad, GstPadProbeInfo *info, gpointer u_data)
buffer = (GstBuffer *)info->data;
map_info = {0};
dmabuf_fd = 0;
gst_buffer_map(buffer, &map_info, GST_MAP_READ);

  ExtractFdFromNvBuffer((void *), &dmabuf_fd);
    egl_image = NvEGLImageFromFd(egl_display, dmabuf_fd);
    status = cuGraphicsEGLRegisterImage(&p_resource, egl_image, CU_GRAPHICS_MAP_RESOURCE_FLAGS_WRITE_DISCARD);

    status = cuGraphicsResourceGetMappedEglFrame(&egl_frame, p_resource, 0, 0);
    status = cuCtxSynchronize();

    cv::cuda::GpuMat d_mat_BGRA(H, W, CV_8UC4, egl_frame.frame.pPitch[0]);

   doing things...

  return GST_PAD_PROBE_OK;

Ok, my doubt is with the following line:

    cv::cuda::GpuMat d_mat_BGRA(H, W, CV_8UC4, egl_frame.frame.pPitch[0]);

I want try to understand why here is CV_8UC4. I have two cameras, one of them is a thermal camera and with this configuration my program doesn’t work. But with my other visible camera, my program it’s works.
When I put the thermal camera, when I try to convert the image to gray with “cvtcolor” for example my program crashes.

I try too putting:

cv::cuda::GpuMat d_mat_BGRA(H, W, CV_8UC1, egl_frame.frame.pPitch[0]);

And the image is correct but when I try to modify it I see the image wrong, as if the image had noise or something similar.

Any help about this topic will be well receive.

Please refer to this sample:

The captured frames from nvarguscamerasrc is in NV12. We need to convert it to RGBA in nvvidconv, and map to OpenCV RGBA buffer. This is the working flow.

Ok, I have another question, I wont to download the gpumat to an another Mat to see it with imshow:

cv::cuda::GpuMat d_mat_BGRA(H, W, CV_8UC4, egl_frame.frame.pPitch[0]);
cv::Mat mat;;
cv::imshow("image", mat);

I get an error that gives me very little information.

OpenCV(4.4.0) /home/nvidia/opencv-4.4.0/opencv-4.4.0/modules/core/src/cuda/ error: (-217:Gpu API call) invalid argument in function 'download'

Any ideas? I start to think that my opencv installation could be the problem.

Per more information,
when I change:
cv::cuda::GpuMat d_mat_BGRA(H, W, CV_8UC4, egl_frame.frame.pPitch[0]); → cv::cuda::GpuMat d_mat_BGRA(H, W, CV_8UC3, egl_frame.frame.pPitch[0]);
My program works, but when I see the stream of the result, the image is not modified. But I know that the image would have to be modified because with the other camera is modified.
It’s like when I switch to CV_8UC3 I can’t ever modify the image but I can visualize it, how can I do it?

We don’t have much experience in cuda filters of OpenCV. Would need other users to share experience. Or go to OpenCV forum.

In the demo code, we utilize sobel filter and it looks working fine.