Skip to content

Instantly share code, notes, and snippets.

@Sitin
Last active December 26, 2015 15:29
Show Gist options
  • Save Sitin/7172726 to your computer and use it in GitHub Desktop.
Save Sitin/7172726 to your computer and use it in GitHub Desktop.
diff --git a/modules/highgui/src/cap_qtkit.mm b/modules/highgui/src/cap_qtkit.mm
index 207f01b..4f7b188 100644
--- a/modules/highgui/src/cap_qtkit.mm
+++ b/modules/highgui/src/cap_qtkit.mm
@@ -277,8 +277,11 @@ bool CvCaptureCAM::grabFrame(double timeOut) {
double sleepTime = 0.005;
double total = 0;
- while (![capture updateImage] && (total += sleepTime)<=timeOut)
- usleep((int)(sleepTime*1000));
+ NSDate *loopUntil = [NSDate dateWithTimeIntervalSinceNow:sleepTime];
+ while (![capture updateImage] && (total += sleepTime)<=timeOut &&
+ [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
+ beforeDate:loopUntil])
+ loopUntil = [NSDate dateWithTimeIntervalSinceNow:sleepTime];
[localpool drain];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment