Use of opencv waitkey() with C++

I'm trying to display the webcam feed with a timer but it doesn't render smoothly. Here is the code :

int timer = 10;
VideoCapture cap(0);
Mat img;

while (true) {
cap.read(img);

if (timer == 0) {
cout << "TIME'S UP !!!" << endl;
}
else if (timer <= 20) {
imshow("Image", img);
waitKey(1);
}
system("cls");
cout << timer-- << " seconds left" << endl;
Sleep(1000);
https://www.imessageapp.org/
}
}
Last edited on
rtfm
https://docs.opencv.org/master/d7/dfc/group__highgui.html#ga5628525ad33f52eab17feebcfba38bd7
> int cv::waitKey (int delay = 0)
> The function waitKey waits for a key event infinitely (when delay≤0 ) or for delay milliseconds

so may simply do while(cv::waitKey(1000./24)) to have ~24 fps
Topic archived. No new replies allowed.