Hello,
I’ve been tasked to create a QByteArray from data acquired by a camear using libargus.
Previously, the data acquired was in RGBA. Then opencv was used to convert it into a cv::Mat in RGB format like so :
// Get NvBuffer from native buffer
m_dmabuf_fd = m_iImageNativeBuffer->createNvBuffer(m_iEGLOutputStream->getResolution(), NvBufferColorFormat_NV12, NvBufferLayout_Pitch);
// Create and extract NvBuffer parameters
NvBufferParams params;
NvBufferGetParams(m_dmabuf_fd, ¶ms);
// Map a pointer to the NvBuffer
void *pointer;
NvBufferMemMap(m_dmabuf_fd, 0, NvBufferMem_Read, &pointer);
// Create and fill an OpenCV matrix
cv::Mat matrix;
opencvMatrix = cv::Mat(*(params.height), *(params.width), CV_8UC4, (char*)(pointer), *(params.pitch));
cv::cvtColor(matrix, matrix, cv::COLOR_RGBA2RGB);
// Fill a QByteArray buffer with the capture informations
QByteArray buffer((char*)(matrix.data), *(params.height) * *(params.width) * 3);
However, I’d like to directly use the nv12 format instead of going with the RGBA then RGB as of now the framework used is compatible with nv12 data.
I changed the creation of the native buffer with :
m_dmabuf_fd = m_iImageNativeBuffer->createNvBuffer(m_iEGLOutputStream->getResolution(), NvBufferColorFormat_NV12, NvBufferLayout_Pitch);
But I don’t know how to create a QByteArray with the acquired data.
I understood that NV12 format is a 2 plane format one for Y and one for UV.
// Create and extract NvBuffer parameters
NvBufferParams params;
NvBufferGetParams(m_dmabuf_fd, ¶ms);
// Map a pointer to the NvBuffer
void* pointer_y;
NvBufferMemMap(m_dmabuf_fd, 0, NvBufferMem_Read, &pointer_y);
void* pointer_uv;
NvBufferMemMap(m_dmabuf_fd, 1, NvBufferMem_Read, &pointer_uv);
Does anyone know how to create a QByteArray then ?