I am attempting to output high resolution imagery in the form of a cv2.cuda_GpuMat() using python.cv2.imshow using a namedWindow flagged with cv2.WINDOW_OPENGL. This does not seem to be functional as the console reports that the feature has not been implemented and to explicitly download using cuda_GpuMat.download(); however, in researching this problem I came across:
Both indicating that cv2.imshow is able to process image mats directly from CUDA/GPU memory.
does this work from C++ (build a small C++ demo file and run it)? if yes, it’s a python bindings issue. if that doesn’t work either, maybe the feature itself doesn’t quite work.
I’m unable to do so, I’m trying to fix an issue on a GPU heavy production media system that’s running a 4K led-wall (and lagging downloading the frames to buffer on CPU. I don’t have the local resources to perform the test.
In short it looks like when OpenCV moved highgui to a plugin architechture the support for GpuMat was not implemented. This can be overcome in C++ by using
however from a quick inspection the cv::ogl::Texture2D api is not exposed to python. Additionaly if Texture2D is wrapped (CV_EXPORTS_W) it can’t be passed to any OpenCV functions as they can’t deal with that type.
Aha! That makes perfect sense! I guess that puts me onto the search for an alternative method, unfortunately I haven’t been able to locate a different solution. Any ideas?
It depends, if your processing a single video stream in a single thread you could try using CUDA streams and displaying the output with a 1 frame delay as I demonstrated in the guide below
I have isolated the delay into two locations, upload is hurting me but that’s torch, and cv is actually way faster, on the download side I’m losing out because I am downloading to CPU and then it’s resizing the image to the display, I have the option of uploading back to GPU but that’s just as bad, I want to convert the memory map from torch to cv and then pipe directly to the output without getting tangled up on the cpu