Hello,
I am using tx2 with this sample →
/usr/src/jetson_multimedia_api/samples/09_camera_jpeg_capture
to get image from csi camera and convert it to a cv::Mat . I convert to mat successfully but it is so slow at cvtColor part.
image resolution is :3840x2160
auto t1 = duration_cast(system_clock::now().time_since_epoch()).count();
IFrame *iFrame = interface_cast<IFrame>(frame);
if (!iFrame)
ORIGINATE_ERROR("Failed to get IFrame interface");
// Get the IImageNativeBuffer extension interface.
NV::IImageNativeBuffer *iNativeBuffer =
interface_cast<NV::IImageNativeBuffer>(iFrame->getImage());
if (!iNativeBuffer)
ORIGINATE_ERROR("IImageNativeBuffer not supported by Image.");
auto t2 = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
int fd = iNativeBuffer->createNvBuffer(m_resolution,
NvBufferColorFormat_ABGR32,
NvBufferLayout_Pitch);
auto t3 = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
void *pdata = NULL;
NvBufferMemMap(fd, 0, NvBufferMem_Read, &pdata);
auto t4 = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
NvBufferMemSyncForCpu(fd, 0, &pdata);
auto t5 = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
mat = cv::Mat(m_resolution.height(),m_resolution.width(), CV_8UC4, pdata);
auto t6 = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
cv::cvtColor(mat, mat, cv::COLOR_BGRA2BGR);
auto t7 = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
NvBufferMemUnMap(fd, 0, &pdata);
t2-t1: 0ms.
t3-t2: 11ms.
t4-t3: 1ms.
t5-t4: 0ms.
t6-t5: 0ms.
t7-t6: 121ms.
When directly converting iFrame to jpeg , it took 20-40ms. So i suprised when i see this result of converting to cv::Mat.
What is the fastest way to get cv::Mat from iFrame object?