I want to display an image in OpenCV in a full screen borderless window.
In other words, only the image pixels will appear, without menu, toolbar, or window background.
Using imshow() or cvShowImage() don’t enable it:
- The window grows to be full screen
in width but not in height. It misses few pixels. - I could not make it borderless even by changing settings of window
handler.
I think that the problem is rooted in cvNamedWindow() method which creates main WS_OVERLAPPED window, then creates a child and all functions like imshow() or cvGetWindowHandle() operate on the child.
Thus even windows command:
SetWindowLong((HWND)cvGetWindowHandle(winName), GWL_STYLE, WS_VISIBLE | WS_EX_TOPMOST | WS_POPUP);
Doesnt help, since the child cannot become borderless WS_POPUP. Someone got a workaround?
- Maybe, showing opencv mat to window
without using opencv built in methods - Or some kind of windows trick
P.S. I tried the following code:
cvMoveWindow("AAA",0,0);
cvSetWindowProperty("AAA", CV_WINDOW_FULLSCREEN, CV_WINDOW_FULLSCREEN);
// Also I tried this:
HWND hwnd = (HWND)cvGetWindowHandle("AAA");
RECT windowRect;
windowRect.left = 0;
windowRect.top = 0;
windowRect.right = cxScreen; //Display resolution
windowRect.bottom = cyScreen; //Display resolution
AdjustWindowRect(&windowRect,WS_VISIBLE,false);
long p_OldWindowStyle = SetWindowLongPtr(hwnd,GWL_STYLE,WS_POPUP);
SetWindowPos(hwnd,HWND_TOP,0,0,windowRect.right,windowRect.bottom,SWP_FRAMECHANGED | SWP_SHOWWINDOW);
SetWindowLong(hwnd, GWL_STYLE, WS_VISIBLE | WS_EX_TOPMOST | WS_POPUP);
Have you issued
cvShowImage()to display the window? Because it seems you are not doing it. Anyway, you might want to call the win32 API for this instead, so add a call toShowWindow(hwnd, SW_SHOW);afterSetWindowPos().If your current call to
SetWindowPos()doesn’t do the trick, check this answer: Hide border of window, if i know a handle of this windowI recommend you doing your tests without calling
cvSetWindowProperty()at first, just to make sure you can find a method that works.Just a note, if you check
modules/highgui/src/window_w32.cppyou can see how OpenCV creates windows on Windows.EDIT:
The following code implements the tips I gave before and bypasses the problems the OP reported. The trick is NOT using
cvGetWindowHandle()to retrieve the windows’ handle and use directly win32 API for that:FindWindow()This code will make the window created by OpenCV borderless, but you still might have to tweak one thing or another to make this operation perfect. You’ll see why. One idea is to resize the window and make it the size of the image.
EDIT:
Well, since you stated:
I also decided to do this last part for you, since I’m such a nice guy =]
This is a small improvement of the code above:
And on my system it displays exactly what you asked on the question.