OpenCV - char 与 int
在《学习 OpenCV》一书中有关阅读 AVI 视频的内容中。
我输入的程序如下:
char c = cvWaitKey(33);
if (c == 27) break;
如您所见,c
被定义为char
。 if-statement
为什么将 c
与 int
进行比较?
并且,当我们有以下语句:char c = cvWaitKey(33);
时,cvWaitKey(33);
返回的char
值是什么? ?
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
char
只是 -128 到 127 之间的数字(如果无符号,则为 0 到 255),通常(但并非总是)表示 ASCII 字符代码。如果整数文字落入有效值范围内(这就是
if
语句中发生的情况),编译器可以毫无问题地将整数文字隐式转换为char
。cvWaitKey
函数返回按下的键的字符代码。 ASCII 字符代码 27 恰好对应于 ESC 键。cvWaitKey
的参数(33)是等待的毫秒数。每帧等待 33 毫秒(这是我期望发生的情况)意味着应用程序以 30 fps 运行。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 theif
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.