Skip to content

highgui: expose VSYNC window property for OpenGL on W32#19408

Merged
opencv-pushbot merged 1 commit intoopencv:masterfrom
crackwitz:ogl-wndprop-vsync
Feb 3, 2021
Merged

highgui: expose VSYNC window property for OpenGL on W32#19408
opencv-pushbot merged 1 commit intoopencv:masterfrom
crackwitz:ogl-wndprop-vsync

Conversation

@crackwitz
Copy link
Copy Markdown
Contributor

@crackwitz crackwitz commented Jan 27, 2021

combined with the proposed zero-delay pollKey alternative to waitKey (separate pull request), disabling VSYNC can drastically speed up display of images. I can get close to 1000 fps for a trivial example (see below), whereas with VSYNC it's nailed to 60 fps (for my screen) and with mandatory Sleep() in waitKey it's throttled to a jittery 100 FPS depending on OS scheduler.

I hope I based this on the right branch. it's not a bug fix. I think I managed to retarget this to the master branch.

I took the implementation of the TOPMOST property as a template and tried to emulate the code structure.

please let me know if I can improve or if this isn't the right way to get such code introduced.

#!/usr/bin/env python3
import time
import numpy as np
import cv2 as cv

cv.namedWindow("window", cv.WINDOW_OPENGL)
print("VSYNC is", cv.getWindowProperty("window", cv.WND_PROP_VSYNC))
cv.setWindowProperty("window", cv.WND_PROP_VSYNC, 0)
print("VSYNC is", cv.getWindowProperty("window", cv.WND_PROP_VSYNC))

i = np.eye(60, dtype=np.uint8) * 255 # cheap barber pole
cnt = 0
t0 = t1 = time.perf_counter()
while True:
	t1 = time.perf_counter()
	if t1 - t0 >= 1.0:
		t0 = t1
		print(cnt, "fps")
		cnt = 0
	i = np.roll(i, shift=1, axis=1) # roll by one column
	cv.imshow("window", i)
	cnt += 1
	key = cv.waitKey(1)
	if key in (13, 27): break

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake
force_builders=Win32,Custom
buildworker:Custom=linux-1,linux-4,linux-6
build_image:Custom=qt:16.04

@crackwitz crackwitz changed the base branch from 3.4 to master January 27, 2021 16:36
@crackwitz crackwitz force-pushed the ogl-wndprop-vsync branch 2 times, most recently from 1237f3d to 2707337 Compare January 27, 2021 19:42
@crackwitz
Copy link
Copy Markdown
Contributor Author

I believe the "OpenCV CN Windows 10 x64" build fails due to some error in the CI. it can't check out from the repo. ERROR: Error fetching remote repo 'origin'

@asmorkalov
Copy link
Copy Markdown
Contributor

@crackwitz Windows 10 x64 fails due to infrastructure issue. I'm working on the problem right now. Please ignore the failed build for now.

@asmorkalov asmorkalov self-requested a review February 3, 2021 07:59
Copy link
Copy Markdown
Contributor

@asmorkalov asmorkalov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done! 👍 Please squash commits to have clear git history after merge.

property getter/setter code conditional on HAVE_OPENGL
getter: return -1 upon specific OpenGL errors
@crackwitz
Copy link
Copy Markdown
Contributor Author

squashed.

@opencv-pushbot opencv-pushbot merged commit 3e34cec into opencv:master Feb 3, 2021
@crackwitz crackwitz deleted the ogl-wndprop-vsync branch February 3, 2021 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants