Opencv cv :: waitKey () return value

I am debugging C ++ code that uses OpenCV on Ubuntu 14, which is known to work on Ubuntu 12, and possibly with another OpenCV library.

What was before

int key_pressed = waitKey(0);
cout << "key_pressed " << int(key_pressed) << endl;
switch( key_pressed )
{
    case 27: //esc
    {
        //close all windows and quit
        destroyAllWindows();
    }

    ...

But this code does not work and I have output key_pressed 1048603

This code work:

char key_pressed = cv::waitKey();
cout << "key_pressed " << int(key_pressed) << endl;
switch( key_pressed )
{
    case 27: //esc
    {
        //close all windows and quit
        destroyAllWindows();
    }

    ...

This code works and I have output key_pressed 27

What could be causing this behavior?

PS documentation says cv :: waitKey () return int, so why do we need to convert it to char?

+4
source share
1 answer

This function is highly dependent on the operating system: / some of them add a bit to an integer ....

ascii , , 27 - ascii ESC...

, , , int char.

: .... ( , )

:

1) char... , ( opencv, )

2) int key = cv::waitKey(1) & 255. ...

, :

You obtained as an int: 1048603
in binary it will be: 00000000 00010000 00000000 00011011
27 in binary is:      00000000 00000000 00000000 00011011

, .... - , 2. 255, 0xEFFFFF,

00000000 11101111 11111111 11111111

?

, , , numslock capslock ctrl... .

+6

All Articles