opencv使用waitKey()函数处理箭头键

Ami*_*ily 8 keyboard opencv

我想处理箭头键.但是当我打印出waitKey()函数的输入值时,它是0.我不知道为什么.我尝试从"int"更改为"char",但它不起作用.我怎么解决这个问题.

int pos = 100;
imshow("image", image);
onChange(pos, (void *)&image);
createTrackbar("threshold", "image", &pos, 255, onChange, (void*)&image);
while (1) {
    int Key = waitKey();
    cout << Key << endl;
    if (Key == 27) break;
    if (Key == 2490368) {
        pos--;
        onChange(pos, (void *)&image);
    }
    if(Key == 2621440){
        pos++;
        onChange(pos, (void *)&image);
    }
    if (pos < 0 || pos > 255) pos = 0;
}
Run Code Online (Sandbox Code Playgroud)

Hea*_*rab 12

请改用waitKeyEx()功能.正如文件所说:

与waitKey()类似,但返回完整的密钥代码.

密钥代码是特定于实现的,取决于使用的后端:QT/GTK/Win32

在我的系统上它给出:左:2424832上:2490368右:2555904下:2621440

虽然有许多在线消息来源说waitKey()使用箭头,但它并没有在我的Windows系统上返回正确的密钥代码(总是返回0).猜猜这也是特定于实现的.也许是因为waitKey()回报ASCII码,但箭头键没有他们(作为解释这里).