OpenCV waitKey 无法正常捕捉方向键(上下左右),总结和解决方案,可以用waitKeyEx

 在win10+python+opencv3.4.5,测试

while True:
    key = cv2.waitKey(0)
    print('key =', key)

依次按上、下、左、右方向键,输出:

key = 0
key = 0
key = 0
key = 0

 

测试代码:

while True:
    key = cv2.waitKeyEx(0)
    print('key =', key)

依次按上、下、左、右方向键,输出:

key = 2490368
key = 2621440
key = 2424832
key = 2555904

 

官方说,waitKeyEx和waitKey类似,Key code is implementation specific and depends on used backend: QT/GTK/Win32/etc

posted @ 2019-01-18 21:21  xbit  阅读(4608)  评论(0编辑  收藏  举报