【问题标题】:Detect a key pressed in dlib.image_window()检测在 dlib.image_window() 中按下的键
【发布时间】:2018-09-24 01:11:48
【问题描述】:

有以下代码:

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”???

【问题讨论】:

    标签: python-3.x opencv dlib


    【解决方案1】:

    你可以用这个:

    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
    

    【讨论】:

    • 我有 ImportError: No module named 'msvcrt'。我想这是因为我在 linux 上。
    猜你喜欢
    • 1970-01-01
    • 2018-10-24
    • 2016-09-25
    • 2014-08-01
    • 1970-01-01
    • 2018-02-15
    • 1970-01-01
    • 1970-01-01
    • 2022-11-17
    相关资源
    最近更新 更多