Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

window_w32.cpp: remove "gutter" #19308

Closed
crackwitz opened this issue Jan 11, 2021 · 8 comments
Closed

window_w32.cpp: remove "gutter" #19308

crackwitz opened this issue Jan 11, 2021 · 8 comments

Comments

@crackwitz
Copy link
Contributor

crackwitz commented Jan 11, 2021

I would like to remove the 1-pixel "gutter" that sits between the displayed image and the window's border in win32 imshow. the function icvCalcWindowRect could either get its gutter constant set to 0 or the entire calculation could be simplified (my preference).

static RECT icvCalcWindowRect( CvWindow* window )
{
const int gutter = 1;
RECT crect = { 0 }, trect = { 0 } , rect = { 0 };
assert(window);
GetClientRect(window->frame, &crect);
if(window->toolbar.toolbar)
{
GetWindowRect(window->toolbar.toolbar, &trect);
icvScreenToClient(window->frame, &trect);
SubtractRect( &rect, &crect, &trect);
}
else
rect = crect;
rect.top += gutter;
rect.left += gutter;
rect.bottom -= gutter;
rect.right -= gutter;
return rect;
}

reason: when you send the window into fullscreen, you'd expect the image area to be the precise resolution of your screen, right? with that gutter, it's not. it's smaller by two pixels (window decoration disappears, the gutter stays). a precisely screen-sized image shown will be slightly off, which either causes rows and columns of the picture to disappear (GDI: nearest neighbor) or the whole picture gets resampled and turned into mush (OpenGL: bilinear). the gutter also has no function that I can see.

import numpy as np
import cv2 as cv
im = np.eye(200)
cv.imshow("gutter?", im)
cv.waitKey(-1)

observe the gray gutter:
close up

my question: would you like the pull request to be against 3.4 or master? I ask because last time I had a pull request against the wrong branch, having to rebase overwhelmed me and I'd like to avoid repeated embarrassment.

@asmorkalov
Copy link
Contributor

@vpisarev could you comment the solution?

@crackwitz
Copy link
Contributor Author

here's a little something you can run that demonstrates the issue:
https://gist.github.com/crackwitz/413bbb458b88772f5912d8af978b0b53
use args --size 2560x1440 --gutter 1 to see a clean pattern with the current situation (size is reduced appropriately for given gutter),
or --size 2560x1440 --gutter 0 to see what happens when you want to display a picture that's actually that size.

@crackwitz
Copy link
Contributor Author

crackwitz commented Jan 18, 2021

if desired, I could extend that code to center the displayed image in the window, and also implement WINDOW_KEEPRATIO for this backend (it's currently acting like FREERATIO, stretching).

@vpisarev
Copy link
Contributor

have no objections to accept the patch

@asmorkalov
Copy link
Contributor

The gutter exists even in opencv_attic repository and looks like some hack for old Windows versions support. The core team discussed the issue and decided that we do not need it any more. Feel free to propose patch that removes extra border.

@crackwitz
Copy link
Contributor Author

crackwitz commented Jan 22, 2021

I'll get it done tonight. would you prefer pull request against master or 3.4 branch? I see the 3.4.14 milestone tag and thought I'd ask.

@alalek
Copy link
Member

alalek commented Jan 22, 2021

Please target PR to 3.4 branch

@crackwitz
Copy link
Contributor Author

crackwitz commented Jan 23, 2021

I am considering looking into making WINDOW_KEEPRATIO work for win32 and accompanying OpenGL mode (currently it behaves like FREERATIO). that will likely involve changes in several functions. I'll work on that and make a separate pull request for that.

I was meaning to run the test I see in the highgui module source... I have told cmake to BUILD_TESTS but the generated VS solution's opencv_tests project looks empty and the RUN_TESTS target doesn't do anything either. just says 1>No tests were found!!!

please feel free to stop me if working on window_w32.cpp is a waste of time. I heard about plans for bigger changes in the highgui module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants