簡體   English   中英

如何在 OpenCV 中顯示圖像和終端

[英]How to display an image and a terminal in OpenCV

如何使用 OpenCV 同時顯示我的網絡攝像頭和終端? 我需要終端運行一些命令來使網絡攝像頭出現,並通過對象檢測執行其他不同的操作。

下面是運行,而在同一時間能夠使用終端網絡攝像頭的一個非常簡單的例子input()通過執行所有OpenCV的幀捕捉,並imshow從一個單獨的線程荷蘭國際集團:

from threading import Thread
import cv2

shouldExit = False
color = True

def cam():
    cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)
    while not shouldExit:
        ret, frame = cap.read()
        if not color:
            frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        cv2.imshow("window title", frame)
        cv2.waitKey(1)
    cap.release()
    cv2.destroyAllWindows()

t = Thread(target=cam)
t.start()

while True:
    print('select an action: q-quit, t-toggle color')
    choice = input(">").strip().lower()
    if choice == 'q':
        shouldExit = True
        t.join()
        break
    elif choice == 't':
        color = not color
    else:
        print('invalid input')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM