How to exit videocapture loop, without using cin

Need to exit videocapture loop, without using cin.
I need to exit to main function with keyboard key or something else
while ( true )
{
capDesktop.read();
cvtColor(capDesktop.image, bgrImg, COLOR_BGRA2BGR);

Why don’t you want to use cin?

An alternative would be to use cv::waitKey() but this will introduce delay, not sure how this will compare to the delay introduced by cin. e.g.

char c = waitKey(1);
if (c == 'q') break;

also requires an imshow window but most people that capture some video might also show it at the same time.

polling cin for available characters probably costs way less than the millisecond incurred by waitKey… but there’s pollKey for that!

2 Likes

Good point, I just assumed it could be used anywhere, but then where would it grab the key input from.