I apologize if this has been asked before, but I wasn’t able to find a suitable solution that worked for us. I’m trying to convert an NvBuffer
decoded using NvJPEGDecoder
into a cv::Mat
with 3 channels (RGB). Here’s how I am doing it currently and it isn’t working.
std::array<unsigned char, MAX_IMAGE_WIDTH * MAX_IMAGE_HEIGHT * 3 / 2> encoded_jpeg_data_buffer;
std::array<unsigned char, MAX_IMAGE_WIDTH * MAX_IMAGE_HEIGHT * 3> decoded_jpeg_data_buffer;
int decoded_dma_buffer_fd = -1;
uint32_t width, height, pixel_format;
if (jpeg_decoder_->decodeToFd(decoded_dma_buffer_fd,
encoded_jpeg_data_buffer.data(), image_size, pixel_format,
width, height) != 0)
{
return false;
}
NvBuffer2Raw(decoded_dma_buffer_fd, NvBufferColorFormat_YUV420, width, height,
decoded_jpeg_data_buffer.data());
...
cv::Mat rgb_mat =
cv::Mat(MAX_IMAGE_HEIGHT, MAX_IMAGE_WIDTH, CV_8UC3, decoded_jpeg_data_buffer.data());
cv::cvtColor(rgb_mat, rgb_mat, cv::COLOR_YUV2RGB);
The encoded_jpeg_data_buffer
contains an image captured using a Camera in Libargus, and was encoded into a JPEG using NvJPEGEncoder
.
What am I doing wrong? Thanks in advance.