简体   繁体   中英

OpenCV - char vs. int

In an from the Learning OpenCV book about reading an AVI video.

The program I typed is as follows:

char c = cvWaitKey(33);
if (c == 27) break;

As you can see, c was defined as char . How come the if-statement is comparing c with an int ?

And, when we have this statement: char c = cvWaitKey(33); , what could the char value returned by cvWaitKey(33); ?

Thanks.

A char is just a number between -128 and 127 (or 0 and 255 if it is unsigned), usually, but not always, representing an ASCII character code.

The compiler has no problems implicitly converting an integer literal to a char if it falls within the valid range of values, which is what happens in the if statement.

The cvWaitKey function returns the character code of the key that was pressed. ASCII character code 27 happens to correspond to the ESC key.

The parameter to cvWaitKey (the 33) is the number of milliseconds to wait. Waiting 33ms on each frame (which is what I expect is happening) means the application is running at 30fps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM