gpt4 book ai didi

python-3.x - 检测在 dlib.image_window() 中按下的键

转载 作者:太空宇宙 更新时间:2023-11-03 21:50:48 25 4
gpt4 key购买 nike

具有以下代码:

import dlib
import cv2
from lib.capture import Capture

win = dlib.image_window()

cap = Capture() # Capture image from webcam
cap.start()

while(True):
frame = cap.get() # Get current frame from webcam
if frame is not None:
frame = cv2.flip(frame, 1)
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR) # Converting from RGB to BGR (as dlib.image_window requires)
win.set_image(frame) # Display the resulting frame

如何检测按下的键,例如dlib 窗口中的“ESC”???

最佳答案

你可以使用这个:

from msvcrt import getch
import dlib
import cv2
from lib.capture import Capture

win = dlib.image_window()

cap = Capture() # Capture image from webcam
cap.start()

while(True):
frame = cap.get() # Get current frame from webcam
if frame is not None:
frame = cv2.flip(frame, 1)
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR) # Converting from RGB to BGR (as dlib.image_window requires)
win.set_image(frame) # Display the resulting frame
key = ord(getch())
if key == 27: #ESC
break

关于python-3.x - 检测在 dlib.image_window() 中按下的键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49821000/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com