Hello,
I am using TX2+argus library+2 Leopard IMX577 cameras to capture images.
I got camera captures in nvbuffer and verified that the image is correct by display it to screen using OpenCV.
My problem is when I transfer the data from nvbuffer to CPU memory, it is really slow. My image size is 4056x3040 and using NvBufferColorFormat_ABGR32 format for nvbuffer(pitch layout is used, pitch=16384). The buffer contains about 47.5MB data for a single capture. And it takes me about 100ms to copy this 47.5MB data to CPU system memory. I have tried memcpy, OpenCV mat::copyTo and NvBuffer2Raw. They are all really slow. Our target is about 10-20ms for copying.
The purpose of this copy is that I need to convert this raw data to cv::Mat afterwards for further processing if necessary, for example, save to disk as jpeg when user requires that etc.
Do you have any solution for this?
Thanks,
Jon
For more details:
I am using the EGLStream to get EGLStream::Frame first. Then get the nv buffer by calling
EGLStream::NV::IImageNativeBuffer *iNativeBuf =interface_cast<EGLStream::NV::IImageNativeBuffer>(eglImage);
Then I create the nv buffer and copy the buffer to the CPU DRAM as following:
if(m_nvBufFd1 == -1)
{
/* m_imgResolution1 is 4056x3040 */
m_nvBufFd1 = iNativeBuf->createNvBuffer(m_imgResolution1, NvBufferColorFormat_ABGR32, NvBufferLayout_Pitch, m_config.m_rotation, &status);
if(m_nvBufFd1 == -1 || status != STATUS_OK)
{
std::err << "Cannot create nv buffer";
}
}
else
{
status = iNativeBuf->copyToNvBuffer(m_nvBufFd1, m_config.m_rotation);
if(status != STATUS_OK)
{
std::err << "Cannot copy to nv buffer left";
}
}
void *pdata = nullptr;
NvBufferMemMap(m_nvBufFd1, 0, NvBufferMem_Read, &pdata);
NvBufferMemSyncForCpu(m_nvBufFd1, 0, &pdata);
unsigned char *p = (unsigned char*)malloc(m_imgResolution1.height() * m_nvBufParam.pitch[0]);
/* !!! HERE IT IS REALLY SLOW !!!!, it takes about 100ms. I have tried memcpy, cv::Mat::copyTo and NvBuffer2Raw*/
int cpRet = NvBuffer2Raw(m_nvBufFd1, 0, m_imgResolution1.width(), m_imgResolution1.height(), p);
if(cpRet == -1)
{
std::err << "NvBuffer2Raw error";
}
free(p);