opencv handling arrow keys with waitKey() function

Viewed 18910

I want to handling arrow keys. but when I print out the input value for waitKey() function, It's 0. I don't know why. I try to change from "int" to "char" , but It doesn't work. How can I solve this problem.

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;
}
4 Answers

Note that this depends on version, on windows with 3.0 waitKey() gave full key codes, but when I changed to 3.3, it suddenly returned 0 for arrow keys.

with waitkey() in your code,keep the left click pressed on the cv2.trackbar icon and use the arrow keys to move in increments of 1

Related