2012-03-23 33 views
1

我使用與Python結合值不是字符代碼

的OpenCV想用下面的代碼

cv.waitkey(10) 

它給按下的鍵的值 - 1,當沒有鍵被擊中時,該值如果有任何鍵被擊中。

-1 
    -1 
    -1 
    536870939 
    -1 
    -1 

任何人都可以幫助我這個請。

非常感謝

+1

也許它關係到[這裏](http://stackoverflow.com/questions/9172170/python-opencv- cv-waitkey-spits-back-weird-output-on-ubuntu-modulo-256-maps-corre)問題? – sietschie 2012-03-23 12:14:45

+0

想要查看再現問題的最小應用程序。 – karlphillip 2012-03-23 12:35:22

+0

請顯示您的代碼,以及您如何使用它。 – fraxel 2012-03-23 12:48:55

回答

2
# While this bug remains unresolved: 
if key != -1: 
    reactTo(key % 256) # Note: NOT 255 
+0

同樣的事情適用於C + +?我試圖抓住'CTRL',但它不起作用。 – IBG 2014-02-14 06:10:32

+0

噢,很不一樣對不起。 – IBG 2014-02-14 06:10:55

0

它爲我的作品:

>>> import cv 
>>> cv.NamedWindow("keypress", 0) 
>>> cv.WaitKey(10000) #then I click on the new window and press the 'f' key 
102 
>>> chr(102) 
'f'  

你需要有一個活動窗口。 看來你的問題可以通過在返回值操作% 255得到解決,ITSA瘋狂bug

+0

鍵%255爲我工作 – Shan 2012-03-23 14:32:49