I’m using Jetson Xavier NX jetpack 4.6 now ,
and really having problem in fetch picture of rgb in nvmemory.
Buffer in the cpu can be get easily , in the gstpad probe.just map the info data.
But the type of nvbuf can’t fetch directly.
I found a useful reference which tell me use function of cudaEGL.h.
static GstPadProbeReturn
conv_src_pad_buffer_probe (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);
//CUDA postprocess
{
EGLImageKHR egl_image;
egl_image = NvEGLImageFromFd(egl_display, dmabuf_fd);
CUresult status;
CUeglFrame eglFrame;
CUgraphicsResource pResource = NULL;
cudaFree(0);
status = cuGraphicsEGLRegisterImage(&pResource,
egl_image,
CU_GRAPHICS_MAP_RESOURCE_FLAGS_NONE);
if (status != CUDA_SUCCESS)
{
printf(“cuGraphicsEGLRegisterImage failed: %d \n”,status);
}
status = cuGraphicsResourceGetMappedEglFrame(&eglFrame, pResource, 0, 0);
status = cuCtxSynchronize();
if (create_filter) {
filter = cv::cuda::createSobelFilter(CV_8UC4, CV_8UC4, 1, 0, 3, 1, cv::BORDER_DEFAULT);
//filter = cv::cuda::createGaussianFilter(CV_8UC4, CV_8UC4, cv::Size(31,31), 0, 0, cv::BORDER_DEFAULT);
create_filter = false;
}
cv::cuda::GpuMat d_mat(h, w, CV_8UC4, eglFrame.frame.pPitch[0]);
filter->apply (d_mat, d_mat);
status = cuCtxSynchronize();
status = cuGraphicsUnregisterResource(pResource);
NvDestroyEGLImage(egl_display, egl_image);
}
gst_buffer_unmap(buffer, &map);
return GST_PAD_PROBE_OK;
}
but it’s handeling the RGBA format.
I need to convert NV12(memory:NVMM) to RGB then save the pic.
So,shall we have a more easy way or introduction to solve the problem ?