Hi, what is now the updated way to populate an OpenCV Matrix using Jetpack 5.1. The method described in Using OpenCV to create cv::Mat objects from images received by the Argus yuvJpeg sample program - #4 by moren1 doesn’t seem to be valid for JP5.1, as we would need to now use NvBufSurf
. Additionally, the color format flags seem to have changed. I do not see the NvBufferColorFormat_ABGR32
enum anymore.
Basically, I’m looking for JP5.1 version of this snippet
// Copy the image into an OpenCV Mat object. Note that OpenCV Matrix objects store the color
// channels in the order of blue, green, and red (hence the "bgr" naming convention).
auto *iNativeBuffer = Argus::interface_cast<EGLStream::NV::IImageNativeBuffer>(iFrame->getImage());
if (!iNativeBuffer) {
ORIGINATE_ERROR("IImageNativeBuffer not supported by Image.");
}
if (m_dmabuf == -1) {
m_dmabuf = iNativeBuffer->createNvBuffer(
streamResolution,
NvBufferColorFormat_ABGR32,
NvBufferLayout_Pitch);
if (m_dmabuf == -1) {
ORIGINATE_ERROR("\tFailed to create NvBuffer\n");
}
}
if (iNativeBuffer->copyToNvBuffer(m_dmabuf) != Argus::STATUS_OK) {
ORIGINATE_ERROR("Failed to copy frame to NvBuffer.");
}
void *pdata = nullptr;
NvBufferParams params;
NvBufferGetParams(m_dmabuf, ¶ms);
NvBufferMemMap(m_dmabuf, plane, NvBufferMem_Read, &pdata);
NvBufferMemSyncForCpu(m_dmabuf, plane, &pdata);
cv::Mat imgbuf = cv::Mat(streamResolution.height(), streamResolution.width(), CV_8UC4, pdata, params.pitch[0]);
cv::cvtColor(imgbuf, bgr, cv::COLOR_RGBA2BGR);
Can you please provide an example that would work with the 09_argus_camera_jpeg sample application? Thank you.