Currently, I was able to convert a NvBuffer directly to CPU opencv Mat by using NvBufferMemMap, NvBufferMemSyncForCpu, NvBufferMemUnMap. I was also able to convert NvBuffer to a OpenCV GpuMat by firstly converting the NvBuffer to CUEglFrame and then to OpenCV GpuMat. The second route is a little redundant cus I need to copy data from NvBuffer to CUEglFrame and then to OpenCV GpuMat. I saw there is also a NvBufferMemSyncForDevice function so i’m wondering if I can do it like the first route directly from NvBuffer to Opencv GpuMat. I quickly tried this API but I got the below error
error: (-217:Gpu API call) invalid argument in function 'download'
Not sure if my usage is correct. Is there any example? Thanks.
This is the code snippet:
void *pdata = NULL;
NvBufferMemMap(fd, 0, NvBufferMem_Read, &pdata);
NvBufferMemSyncForDevice(fd, 0, &pdata);
cv::cuda::GpuMat imgBuf = cv::cuda::GpuMat(512,
512,
CV_8UC4, pdata);
cv::Mat cpuImgBuf;
bb.download(cpuImgBuf);
NvBufferMemUnMap(fd, 0, &pdata);
If I change the NvBufferMemSyncForDevice to NvBufferMemSyncForCpu, it works