From 8620bd5a84b03933fe24a3d8ba50715b617837b0 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Thu, 7 Jun 2018 19:25:01 +0300 Subject: [PATCH] highgui(win32): improve waitKey() timeout condition - use cv::getTickCount() instead of Win32 GetTickCount() - process message queue before timeout exit --- modules/highgui/src/window_w32.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/highgui/src/window_w32.cpp b/modules/highgui/src/window_w32.cpp index 5df18b3c03..ea7b461f90 100644 --- a/modules/highgui/src/window_w32.cpp +++ b/modules/highgui/src/window_w32.cpp @@ -1965,7 +1965,8 @@ static void showSaveDialog(CvWindow* window) CV_IMPL int cvWaitKey( int delay ) { - int time0 = GetTickCount(); + int64 time0 = cv::getTickCount(); + int64 timeEnd = time0 + (int64)(delay * 0.001f * cv::getTickFrequency()); for(;;) { @@ -1973,13 +1974,13 @@ cvWaitKey( int delay ) MSG message; int is_processed = 0; - if( (delay > 0 && abs((int)(GetTickCount() - time0)) >= delay) || hg_windows == 0 ) - return -1; - if( delay <= 0 ) GetMessage(&message, 0, 0, 0); else if( PeekMessage(&message, 0, 0, 0, PM_REMOVE) == FALSE ) { + int64 t = cv::getTickCount(); + if (t - timeEnd >= 0) + return -1; // no messages and no more time Sleep(1); continue; } -- GitLab