Convert Argus EGL image buffer to opencv mat

I need to get the argus camera image in RGB format.

I am getting the argus image like this, and want to convert the YUV image to RGB.

Image *image = iFrame->getImage();
IImage *iImage = interface_cast<IImage>(image);
IImage2D *iImage2D = interface_cast<IImage2D>(image);

From here I am trying to create the Y and UV mats, but the data is in some weird format

IImage(2D): buffer 0 (4032x3040, 4032 stride, 12451840 bytes
IImage(2D): buffer 1 (2016x1520, 4032 stride), 6291456 bytes

And OpenCV Mat is not able to read the data.

Can you give me some idea of how this buffer is structured and if there is a way to create OpenCV Mat from this?

Do you check the yuvJpeg sample in the MMAPI.


Thank you for your response.

Yes, I am exactly using that example as a starting pint.

It uses JPG encoder to save the image in a file, but I need to get the data real-time and avoid encoding latencies, unfortunately I did not find any examples of reading the RGB data from IImage2d.

There is another example which requests RGB data instead (demosaicOutput), which uses PIXEL_FMT_LegacyRGBA but this does not work for getting more than one frame, in the same example for the setting PIXEL_FMT_YCbCr_420_888, works properly in a loop, but RGBA format freezes on the second iFrameConsumer->acquireFrame request.

How about below topic.

Thank you for your response, the link there seems corrupted.

here is another thing I was trying

            Image *image = iFrame->getImage();
            IImage *iImage = interface_cast<IImage>(image);
            IImage2D *iImage2D = interface_cast<IImage2D>(image);

            int planeIdx = 0;
            const uint8_t *d = static_cast<const uint8_t *>(iImage->mapBuffer(planeIdx));

            if (!d)
                ORIGINATE_ERROR("\tFailed to map buffer\n");

            Size2D<uint32_t> size = iImage2D->getSize(planeIdx);

            cv::Mat yChannel(size.height(), size.width(), CV_8UC1 , (void *)d, iImage2D->getStride(planeIdx));
            cv::imwrite("test.jpg", Channel);

And getting a result like this.

is there any known documentation samples, how the data is stored in image buffers?

Please check this patch and apply to your application:
How to create OpenCV cv::Mat from NvBuffer in Jetpack 5.1 - #8 by DaveYYY