In 18.04 opencv waitKey loop exit immediately

I have compiled and linked example from Example sourceSuccessfully. In Ubuntu 16.03 begin to work after entering user to group video. I did the same in 18.04 but program exits immediately.

I try to debug code and discovered that problem is waitKey. If i change

if(waitKey(30) >= 0) break;

to

waitKey(30);

It works, but not correctly. How to correctly change the code?

1

1 Answer

Obviously API implementation changed from 2.4.9 to 3.2 so example needs to be corrected.

In ver. 2.4.9 when no key pressed in x ms time returns -1

In ver. 3.2 when no key pressed in x ms time returns 255

So code for both versions for me looks like this:

int k; // key
k=waitKey(30);
if( 255!=k && -1!=k ) break;

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like