目录
监听左右方向键
import cv2
import numpy as np
# 创建一个空白图像
image = np.ones((500, 500, 3), dtype=np.uint8) * 255
# 当前显示的文本
text = "Press Left or Right Arrow Key"
# 监听键盘按键
while True:
# 显示图像并更新文本
cv2.putText(image, text, (100, 250), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 0), 2)
cv2.imshow("Arrow Key Listener", image)
# 等待键盘按键
key = cv2.waitKey(1) & 0xFF
# 判断按下的是哪个键
if key == 81: # Left Arrow key (虚拟键码 81)
text = "Left Arrow Pressed!"
elif key == 83: # Right Arrow key (虚拟键码 83)
text = "Right Arrow Pressed!"
elif k
该博客介绍了如何结合OpenCV和pyinput库在Python中实现对小键盘输入的监听,包括读取图片并进行可视化操作。
订阅专栏 解锁全文
771

被折叠的 条评论
为什么被折叠?



