I'm trying to capture the pixels of an OpenGL application (specifically, MEmu) and later convert it to an OpenCV Mat. I used the hwnd2mat()
function from this post as a reference but ran into some problems.
Only the window frame is captured, as seen here:
Further investigation led me to believe that the problem is that StretchBlt
(or BitBlt
) can't capture the OpenGL pixels.
I tried to use glReadPixels
(and convert to Mat using this), but it is not reading any pixels. The wglCreateContext
returns NULL
, probably because my application does not own the DC of MEmu. Therefore, wglMakeCurrent
does nothing and the pixels are not read.
I was able to create a workaround modified version of hwnd2mat
that gets the WindowRect of MEmu's hwnd but later uses GetDC(NULL)
to capture only the portion of the screen where MEmu is located. This works but any windows that get on top of MEmu get captured aswell.
I can work with this, sure, but was wondering if there is a way to use glReadPixels on a window that I don't own or a way to ensure that hwnd2mat works on the contents of the window that is using OpenGL.