opencv中waitKey函数,在等待ms,返回键盘按键对应的ASCII码。若超过等待时间,则返回-1;ASCII码表如下:
链接: ASCII表.
/* 键盘响应 */
void OpencvExample::Example_WaitKey(Mat &image)
{
Mat dst = Mat::zeros(image.size(), image.type());
while (true)
{
int key = waitKey(100);
cout << key << endl;
if (27 == key) { //esc
break;
}
if (49 == key)//数字1
{
cout << "========1=======" << endl;
cvtColor(image, dst, COLOR_BGR2GRAY);
}
if (50 == key)//数字2
{
cout << "========2=======" << endl;
cvtColor(image, dst, COLOR_BGR2HSV);
}
if (51 == key)//数字3
{
cout << "========3=======" << endl;
addWeighted(image, 1.0, 0, 0, 50, dst);
}
//if (-1 == key)
//{
// cout << "waiting keypress..." << endl;
//}
imshow("KewBoard Response", dst);
}
}