I am using this code to map from nvsufracebuffer to opencv GPU mat
for (int i = 0; i < surface->numFilled; i++) {
// GST_DEBUG("NvBufSurfaceMapEglImage: %d", i);
auto registerStart = std::chrono::high_resolution_clock::now();
status = cuGraphicsEGLRegisterImage(&resources[i],
surface->surfaceList[i].mappedAddr.eglImage, CU_GRAPHICS_MAP_RESOURCE_FLAGS_NONE);
if (status != CUDA_SUCCESS) {
GST_ERROR("cuGraphicsEGLRegisterImage failed: %d", status);
break;
}
registered[i] = true;
// map egl image for every call
// GST_DEBUG("cuGraphicsResourceGetMappedEglFrame: %d", i);
status = cuGraphicsResourceGetMappedEglFrame(&frames[i], resources[i], 0, 0);
if (status != CUDA_SUCCESS) {
GST_ERROR("cuGraphicsResourceGetMappedEglFrame failed: %d", status);
break;
}
auto registerEnd = std::chrono::high_resolution_clock::now();
auto registerDuration = std::chrono::duration_cast<std::chrono::microseconds>(registerEnd - registerStart);
GST_INFO("cuGraphicsResourceGetMappedEglFrame took %ld microseconds", registerDuration.count());
int stream_i = stream_idx.empty() ? i : stream_idx[i];
assert(stream_i < surface->batchSize);
mats[stream_i] = cv::cuda::GpuMat(frames[i].height, frames[i].width, CV_8UC4,
frames[i].frame.pPitch[0], frames[i].pitch);
}
I have 3 4k 30 fps streams and cuGraphicsEGLRegisterImage
takes a pretty long time, is there a way to avoid calling cuGraphicsEGLRegisterImage for every frame and doing it only once at the start ?