NVBuffer (FD) to opencv Mat

Hi,
We don’t observe the issue by applying following patch to 13_multi_camera:

diff --git a/multimedia_api/ll_samples/samples/13_multi_camera/main.cpp b/multimedia_api/ll_samples/samples/13_multi_camera/main.cpp
index 49a9ab8..0613f0b 100644
--- a/multimedia_api/ll_samples/samples/13_multi_camera/main.cpp
+++ b/multimedia_api/ll_samples/samples/13_multi_camera/main.cpp
@@ -39,6 +39,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include <opencv2/opencv.hpp>
+
 using namespace Argus;
 using namespace EGLStream;
 
@@ -259,7 +261,7 @@ bool ConsumerThread::threadInitialize()
     input_params.width = STREAM_SIZE.width();
     input_params.height = STREAM_SIZE.height();
     input_params.layout = NvBufferLayout_Pitch;
-    input_params.colorFormat = NvBufferColorFormat_NV12;
+    input_params.colorFormat = NvBufferColorFormat_ABGR32;
     input_params.nvbuf_tag = NvBufferTag_VIDEO_CONVERT;
 
     NvBufferCreateEx (&m_compositedFrame, &input_params);
@@ -333,8 +335,8 @@ bool ConsumerThread::threadExecute()
             if (!m_dmabufs[i])
             {
                 m_dmabufs[i] = iNativeBuffer->createNvBuffer(iEglOutputStreams[i]->getResolution(),
-                                                          NvBufferColorFormat_YUV420,
-                                                          NvBufferLayout_BlockLinear);
+                                                          NvBufferColorFormat_ABGR32,
+                                                          NvBufferLayout_Pitch);
                 if (!m_dmabufs[i])
                     CONSUMER_PRINT("\tFailed to create NvBuffer\n");
             }
@@ -349,7 +351,21 @@ bool ConsumerThread::threadExecute()
         {
             // Composite multiple input to one frame
             NvBufferComposite(m_dmabufs, m_compositedFrame, &m_compositeParam);
-            g_renderer->render(m_compositedFrame);
+            void *pdata = NULL;
+
+            NvBufferMemMap(m_compositedFrame, 0, NvBufferMem_Read, &pdata);
+            NvBufferMemSyncForCpu(m_compositedFrame, 0, &pdata);
+
+            cv::Mat imgbuf = cv::Mat(STREAM_SIZE.height(),
+                                     STREAM_SIZE.width(),
+                                     CV_8UC4, pdata);
+            cv::Mat display_img;
+            cvtColor(imgbuf, display_img, CV_RGBA2BGR);
+
+            NvBufferMemUnMap(m_compositedFrame, 0, &pdata);
+
+            cv::imshow("img", display_img);
+            cv::waitKey(1);
         }
         else
             g_renderer->render(m_dmabufs[0]);

Makefile:

+CPPFLAGS+=`pkg-config --cflags opencv`
+LDFLAGS+=`pkg-config --libs opencv`

Maybe certain parameters in NvBufferCompositeParams are not well configured in your implementation?

1 Like
NV Multimedia API with OpenCV
How to use decodeToFd transform NvBuffer* to opencv mat in jpegdecoder?
How to pass to hardware encoder from OpenCV
Jetson_multimedia_api NvBufferMem Transform to opencv mat
How to convert a decoded JPEG NvBuffer into OpenCV Mat?
Adding opencv package to Argus Samples
From NvBuffer to cvMat BGRA
Improving GSTreamer and OpenCV performance in Nvidia Jetson TX2
NvBuffer to OpenCV GpuMat. Does memory is directly accessible to the device?
Get plane data
OpenCV Mat Object And Saving Image Data 09_camera_jepg_capture
How do I read the pixel data from an NVBuffer?
Need help to convert nvbuffer to cv::mat using libargus on TX2
Getting image from CSI and sending it to OpenCV does not give correct image
V4l2 Multimedia api and opencv
Copy camera capture from nvbuffer to CPU DRAM is very slow using argus library
About 04_video_dec_trt dec dma data difference with the opencv
How to get opencv images from argus/syncsensor sample?
Getting pointer from NvBuffer
Getting pointer from NvBuffer
Argus,Open CV,RGB image
Opencv gpu mat into GStreamer without downloading to cpu
The image of AR0233 have lag
LibArgus OpenCV live video feed
Using libargus producer thread with multiple opencv consumer threads
How can I get camera preview frame from libargus to do other oparation on it?
Convert NvBuffer to cv::Mat
Using OpenCV to create cv::Mat objects from images received by the Argus yuvJpeg sample program
Getting image to a pointer from frame without memory copy
Libargus Invalid BufferType Error
How to create OpenCV cv::Mat from NvBuffer in Jetpack 5.1
Sending 12-bit images from Libargus to ROS
Create cv::Mat from nvBufferMem cause Segmentation fault (core dump)
Saving m_dmabuf into OpenCV Mat Object in 09_camera_jpeg_capture example
Use opencv to display
Recommended libraries for real-time video image display with overlayed annotations
TX2 decide H264 with tegra_multimedia_api
NvTransform fails on color format transformation
Run Multiple Computer Vision Cameras on one Jetson Nano board
LibArgus EGLStream to nvivafilter