Hi,
I’m trying to handle a gpumat from a gstreamer pipeline. My code is the following:
static GstPadProbeReturn frame_processing (GstPad * pad, GstPadProbeInfo * info, gpointer u_data)
{
GstBuffer *buffer=(GstBuffer *) info->data;
GstMapInfo map={0};
int dmabuf_fd=0;
gst_buffer_map (buffer, &map, GST_MAP_READ);
ExtractFdFromNvBuffer((void *)map.data, &dmabuf_fd);
{
EGLImageKHR egl_image;
egl_image=NvEGLImageFromFd(egl_display, dmabuf_fd);
CUresult status;
CUeglFrame egl_frame;
CUgraphicsResource p_resource=NULL;
cudaFree(0);
status=cuGraphicsEGLRegisterImage(&p_resource, egl_image, CU_GRAPHICS_MAP_RESOURCE_FLAGS_NONE);
status=cuGraphicsResourceGetMappedEglFrame(&egl_frame, p_resource, 0, 0);
status=cuCtxSynchronize();
cv::cuda::GpuMat d_mat(H, W, CV_8UC4, egl_frame.frame.pPitch[0]);
cuda::cvtColor(d_mat, d_mat,cv::COLOR_BGRA2GRAY);
cv::Mat img;
d_mat.download(img);
circle(img, cv::Point(500,500), 300, cv::Scalar(0,255,0),-1);
d_mat.upload(img);
status=cuCtxSynchronize();
status=cuGraphicsUnregisterResource(p_resource);
}
gst_buffer_unmap(buffer, &map);
return GST_PAD_PROBE_OK;
}
And this code is calling with:
gst_pad_add_probe (src_pad, GST_PAD_PROBE_TYPE_BUFFER, frame_processing, NULL, NULL);
I know the code doesn’t make a lot of sense, but I want to understand how that works.
My problem is that with this code, I never see the circle in the image and the image always has 4 color channels.
But if I remove
cuda::cvtColor(d_mat, d_mat,cv::COLOR_BGRA2GRAY);
I always see the circle in the image.
I don’t understand what is the problem with cvtColor.
Does anyone have any idea?
Thanks in advance