简体   繁体   English

OpenCV - char vs. int

[英]OpenCV - char vs. int

In an from the Learning OpenCV book about reading an AVI video. 来自Learning OpenCV一本关于阅读AVI视频的书。

The program I typed is as follows: 我输入的程序如下:

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

As you can see, c was defined as char . 如您所见, c被定义为char How come the if-statement is comparing c with an int ? 为什么if-statementcint进行比较?

And, when we have this statement: char c = cvWaitKey(33); 并且,当我们有这个陈述时: char c = cvWaitKey(33); , what could the char value returned by cvWaitKey(33); cvWaitKey(33);返回的char值是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. char只是介于-128和127之间的数字(如果是无符号,则为0到255),通常(但不总是)表示ASCII字符代码。

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. 如果编译器属于有效的值范围,则编译器可以隐式地将整数文字转换为char ,这就是if语句中发生的情况。

The cvWaitKey function returns the character code of the key that was pressed. cvWaitKey函数返回按下的键的字符代码。 ASCII character code 27 happens to correspond to the ESC key. ASCII字符代码27碰巧对应于ESC键。

The parameter to cvWaitKey (the 33) is the number of milliseconds to wait. cvWaitKey (33)的参数是等待的毫秒数。 Waiting 33ms on each frame (which is what I expect is happening) means the application is running at 30fps. 每帧等待33ms(这是我期望发生的)意味着应用程序以30fps运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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