Using the waitKey() function in opencv under Linux returns a value of 255

1.Usage of waitKey;

C++: int waitKey(int delay=0)

Function function:

Continuously refresh the image, the frequency is delay, the unit is milliseconds (ms), and the return value is the key value of the current keyboard;

Wait for delay > 0 milliseconds. If a key is pressed during this period, it will end immediately and return the ASCII code of the pressed key. Otherwise, the return value is -1; if delay = 0 milliseconds, wait indefinitely until a key is pressed. until;

waitKey only works on the window mechanism, that is, the window generated by nameWindow or imshow;

Note: The return value of waitKey is of type int.

Usage issues: Use in linux system

if(waitKey(5)>=0) break; The original intention is to break out of the loop when a key is pressed. When no key is pressed, the return value of waitKey(5) is -1 and does not enter the if. However, the program ran directly into the if branch. Later, it was verified that the return value of waitKey(5) was 255.

Adjust the code if(waitKey(5)!=255) break; to achieve my own requirements;
record it!

Guess you like

Origin blog.csdn.net/m0_58530510/article/details/130400964