Tuesday 19 April 2011

cvWaitKey return value


If you program with OpenCV, probably you heard about the function cvWaitKey(int delay = 0). Its purpose is to handle keyboard events. The input parameter is documented, but the return values are not.

As I wrote a program that needs to handle keyboard events, and lots of keys are used, I wrote a C header file with all the returned values I could find.

Usage is as follows:

Create an integer variable to hold the returned value.
int key

Grab the key using the function cvWaitKey.
key = cvWaitKey(delay)

The returned value is an integer where the 16 least significant bits hold the key pressed. The other bits indicate if the key was pressed together with an Left Alt, Right Alt, Shift or Control, and the state of Scroll Lock, Caps Lock and Num Lock. There are a few macros that do it. The macro cvKey return the key pressed so you can compare with the constants that name each key.
if cvKeyShiftOn(key){
if (cvKey(key) == CV_KEY_F1){
...
}
}

The file cvkey.h is as follows:

/* dantasu.blogspot.com
April 14, 2011
*/

#define CV_KEY_RALT_ON 0x800000
#define CV_KEY_ALT_ON 0x880000
#define CV_KEY_SCROLLLOCK_ON 0x800000
#define CV_KEY_NUMLOCK_ON 0x100000
#define CV_KEY_LALT_ON 0x80000
#define CV_KEY_CTRL_ON 0x40000
#define CV_KEY_CAPSLOCK_ON 0x20000
#define CV_KEY_SHIFT_ON 0x10000

#define cvKey(x) (x & 0xffff)
#define cvKeyShiftOn(x) (x & CV_KEY_SHIFT_ON)
#define cvKeyCtrlOn(x) (x & CV_KEY_CTRL_ON)
#define cvKeyLaltOn(x) (x & CV_KEY_LALT_ON)
#define cvKeyRaltOn(x) (x & CV_KEY_RALT_ON)
#define cvKeyAltOn(x) (x & CV_KEY_ALT_ON)
#define cvKeyScrollLockOn(x) (x & CV_KEY_SCROLLLOCK_ON)
#define cvKeyCapsLockOn(x) (x & CV_KEY_CAPSLOCK_ON)
#define cvKeyNumLockOn(x) (x & CV_KEY_NUMLOCK_ON)

#define cvPrintKey(x) {if (cvKey(x) < 256){ printf("%c\n", cvKey(x));}}

#define CV_KEY_LWINDOWS 0xffeb
#define CV_KEY_RWINDOWS 0xffec
#define CV_KEY_MENU 0xff67

#define CV_KEY_LALT 0xffe9
#define CV_KEY_RALT 0xfe03

#define CV_KEY_BACKSPACE 0xff08
#define CV_KEY_BREAK 0xff13
#define CV_KEY_SCROLLLOCK 0xff14
#define CV_KEY_NUMLOCK 0xff7f
#define CV_KEY_LSHIFT 0xffe1
#define CV_KEY_RSHIFT 0xffe2
#define CV_KEY_LCTRL 0xffe3
#define CV_KEY_RCTRL 0xffe4
#define CV_KEY_CAPSLOCK 0xffe5

#define CV_KEY_HOME 0xff50
#define CV_KEY_END 0xff57
#define CV_KEY_INSERT 0xff63
#define CV_KEY_DELETE 0xffff
#define CV_KEY_PGUP 0xff55
#define CV_KEY_PGDOWN 0xff56

#define CV_KEY_F1 0xffbe
#define CV_KEY_F2 0xffbf
#define CV_KEY_F3 0xffc0
#define CV_KEY_F4 0xffc1
#define CV_KEY_F5 0xffc2
#define CV_KEY_F6 0xffc3
#define CV_KEY_F7 0xffc4
#define CV_KEY_F8 0xffc5
#define CV_KEY_F9 0xffc6
#define CV_KEY_F10 0xffc7
#define CV_KEY_F11 0xffc8
#define CV_KEY_F12 0xffc9

#define CV_KEY_LEFT 0xff51
#define CV_KEY_UP 0xff52
#define CV_KEY_RIGHT 0xff53
#define CV_KEY_DOWN 0xff54

#define CV_KEY_PLUS 0x002b
#define CV_KEY_MINUS 0x002d
#define CV_KEY_KPAD_PLUS 0xffab
#define CV_KEY_KPAD_MINUS 0xffad
#define CV_KEY_KPAD_ASTERISK 0xffaa
#define CV_KEY_KPAD_SLASH 0xffaf
#define CV_KEY_KPAD_ENTER 0xff8d

#define CV_KEY_NONE 0x0001
#define CV_KEY_TAB 0x0009
#define CV_KEY_ENTER 0x000a
#define CV_KEY_ESC 0x001b
#define CV_KEY_SPACE 0x0020
#define CV_KEY_EXCLAMATION 0x0021
#define CV_KEY_QUOTATION 0x0022
#define CV_KEY_NUMBER 0x0023
#define CV_KEY_DOLLAR 0x0024
#define CV_KEY_PERCENT 0x0025
#define CV_KEY_AMPERSAND 0x0026
#define CV_KEY_APOSTROPHE 0x0027
#define CV_KEY_LPARENTHESIS 0x0028
#define CV_KEY_RPARENTHESIS 0x0029
#define CV_KEY_ASTERISK 0x002a
#define CV_KEY_COMMA 0x002c
#define CV_KEY_DOT 0x002e
#define CV_KEY_SLASH 0x002f
#define CV_KEY_COLON 0x003a
#define CV_KEY_SEMICOLON 0x003b
#define CV_KEY_LESSTHAN 0x003c
#define CV_KEY_EQUALS 0x003d
#define CV_KEY_GREATERTHAN 0x003e
#define CV_KEY_QUESTION 0x003f
#define CV_KEY_AT 0x0040
#define CV_KEY_LSQUARE 0x005b
#define CV_KEY_BACKSLASH 0x005c
#define CV_KEY_RSQUARE 0x005d
#define CV_KEY_UNDERSCORE 0x005f
#define CV_KEY_LCURLY 0x007b
#define CV_KEY_VLINE 0x007c
#define CV_KEY_RCURLY 0x007d

#define CV_KEY_GRAVE 0xfe50
#define CV_KEY_ACUTE 0xfe51
#define CV_KEY_CIRCUMFLEX 0xfe52
#define CV_KEY_TILDE 0xfe53


#define CV_KEY_0 0x0030
#define CV_KEY_1 0x0031
#define CV_KEY_2 0x0032
#define CV_KEY_3 0x0033
#define CV_KEY_4 0x0034
#define CV_KEY_5 0x0035
#define CV_KEY_6 0x0036
#define CV_KEY_7 0x0037
#define CV_KEY_8 0x0038
#define CV_KEY_9 0x0039

#define CV_KEY_KPAD_0 0xffb0
#define CV_KEY_KPAD_1 0xffb1
#define CV_KEY_KPAD_2 0xffb2
#define CV_KEY_KPAD_3 0xffb3
#define CV_KEY_KPAD_4 0xffb4
#define CV_KEY_KPAD_5 0xffb5
#define CV_KEY_KPAD_6 0xffb6
#define CV_KEY_KPAD_7 0xffb7
#define CV_KEY_KPAD_8 0xffb8
#define CV_KEY_KPAD_9 0xffb9


#define CV_KEY_a 0x0061
#define CV_KEY_b 0x0062
#define CV_KEY_c 0x0063
#define CV_KEY_d 0x0064
#define CV_KEY_e 0x0065
#define CV_KEY_f 0x0066
#define CV_KEY_g 0x0067
#define CV_KEY_h 0x0068
#define CV_KEY_i 0x0069
#define CV_KEY_j 0x006a
#define CV_KEY_k 0x006b
#define CV_KEY_l 0x006c
#define CV_KEY_m 0x006d
#define CV_KEY_n 0x006e
#define CV_KEY_o 0x006f
#define CV_KEY_p 0x0070
#define CV_KEY_q 0x0071
#define CV_KEY_r 0x0072
#define CV_KEY_s 0x0073
#define CV_KEY_t 0x0074
#define CV_KEY_u 0x0075
#define CV_KEY_v 0x0076
#define CV_KEY_w 0x0077
#define CV_KEY_x 0x0078
#define CV_KEY_y 0x0079
#define CV_KEY_z 0x007a

#define CV_KEY_A 0x0041
#define CV_KEY_B 0x0042
#define CV_KEY_C 0x0043
#define CV_KEY_D 0x0044
#define CV_KEY_E 0x0045
#define CV_KEY_F 0x0046
#define CV_KEY_G 0x0047
#define CV_KEY_H 0x0048
#define CV_KEY_I 0x0049
#define CV_KEY_J 0x004a
#define CV_KEY_K 0x004b
#define CV_KEY_L 0x004c
#define CV_KEY_M 0x004d
#define CV_KEY_N 0x004e
#define CV_KEY_O 0x004f
#define CV_KEY_P 0x0050
#define CV_KEY_Q 0x0051
#define CV_KEY_R 0x0052
#define CV_KEY_S 0x0053
#define CV_KEY_T 0x0054
#define CV_KEY_U 0x0055
#define CV_KEY_V 0x0056
#define CV_KEY_W 0x0057
#define CV_KEY_X 0x0058
#define CV_KEY_Y 0x0059
#define CV_KEY_Z 0x005a

#define CV_KEY_cedil 0x00e7
#define CV_KEY_CEDIL 0x00c7

//EOF




Wednesday 23 March 2011

flashplayer on Ubuntu 64 (lucid)

After weeks without getting flashplayer to work with my firefox 64 on a Ubuntu 10.04 machine, I finally found a way to solve the problem almost instantly. Just by installing google-chrome.

1 - Go to page labs.adobe.com/downloads/flashplayer10_square.html and download plugin for 64-bit linux.

2 - Uncompress the file and save libflashplayer.so anywhere in the system

3 - Go to page www.google.com/chrome/ and donwload google-chrome installer 64-bit .deb installer for Ubuntu

4 - Run the command below. Somehow, the installer managed to find the libflashplayer.so file.
sudo dpkg -i google-chrome-stable_current_amd64.deb

5 - Say goodbye to firefox 64-bit.

Saturday 19 March 2011

Offtopic: Ubuntu 10 with traditional look and feel.

Ubuntu 10 changed radically it's visual identity. It was quite a break. The look and feel is completely different and probably pleased many people. For those who didn't like the change, it is possible to go back to the traditional appearance. No downgrading required.

Just changing the theme of the desktop, the overall appearance of the desktop goes back to what we are used to. The steps are as follows:
- right click on the desktop
- "change desktop background"
- "Theme"
- "human-clearlooks"

The orthodox purist may want to change even the appearance of the login screen. If you have any hint, please post here in the comments.