In 18.04 Opencv waitKey Loop Exit Immediately

I have compiled and linked example from Example source Successfully. 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

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

Marcus Vance

Marcus Vance

Cybersecurity & Digital Privacy Researcher

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.

Share this article
Twitter Facebook Pinterest