I am developing an application to do some video processing. For the use case, I am grabbing a video stream using the V4l2 direct interface (example 12_camera_v4l2_cuda).
In the end, my goal is to get a pointer in order to do some more processing with opencv and avoid memory copies.
The output of that example I mentioned is a NvBuffer file descriptor. What is the best way to get a pointer out of that? Is this the best way to get the best performance?
However, I have a small difference and question. Since I am having a latency critical iamge application, I need to avoid color conversions, and my camera has YUV 422 format. Is there any way to map the buffer without converting it to RGB?
Hi,
We know that BGR format is common in OpenCV. Not sure about YUV422 formats. If the formats are supported same as BGR, you can try the same to map NvBuffer to cv::Mat.
Thanks for reply. Since I am interested in cv::GpuMat, I have followed the following approach based on the different forums that you have shared:
NvBuffer → EGLImage → EGLFrame → OpenCV Gpu Mat
Here is the example code:
/* Convert the camera buffer from YUV422 to YUV420P */
if (-1 == NvBufferTransform(cameraAcquireParams->g_buff[v4l2_buf.index].dmabuff_fd, cameraAcquireParams->render_dmabuf_fd,
&transParams))
ERROR_RETURN("Failed to convert the buffer");
/* Create EGLImage from dmabuf fd */
cameraAcquireParams->egl_image = NvEGLImageFromFd(cameraAcquireParams->egl_display, cameraAcquireParams->render_dmabuf_fd);
if (cameraAcquireParams->egl_image == NULL)
ERROR_RETURN("Failed to map dmabuf fd (0x%X) to EGLImage",
cameraAcquireParams->render_dmabuf_fd);
/* Create EglFrame from EGL Image*/
CUresult status;
CUeglFrame myframe;
CUgraphicsResource pResource = NULL;
cudaFree(0);
status = cuGraphicsEGLRegisterImage(&pResource, cameraAcquireParams->egl_image,
CU_GRAPHICS_MAP_RESOURCE_FLAGS_NONE);
if (status != CUDA_SUCCESS)
{
printf("cuGraphicsEGLRegisterImage failed: %d, cuda process stop\n",
status);
break;
}
status = cuGraphicsResourceGetMappedEglFrame(&myframe, pResource, 0, 0);
if (status != CUDA_SUCCESS)
{
printf("cuGraphicsSubResourceGetMappedArray failed\n");
break;
}
My question is, I do not really know if this would be the correct approach for handling the image into a Gpu Mat. Would this be correct? It seems like it is performing copy operations, but I really do not know this.