簡體   English   中英

結合OpenCV,Python,Tkinter和PiCamera

[英]Combining OpenCV, Python, Tkinter and PiCamera

我在程序中使用OpenCV,Python,Tkinter和PiCamera時遇到問題。

  • Tkinter窗口用於顯示和設置要在OpenCV中使用的值:

    TkinterWindow

  • 我正在嘗試不斷讀取和處理我正在使用的PiCamera的視頻提要:

     while True: for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True): root.update_idletasks() 

但是在互聯網上閱讀一番后,我發現不建議使用update() ,因此我嘗試了運氣以了解線程,但失敗了。 VideoCapture()有很多示例,這些示例可用於USB攝像機,但不能用於PiCamera。 除了線程之外,還有其他方法嗎?

您可以使用root.after(...) 下面是一個示例代碼:

# define a variable used to stop the image capture
do_image_capture = True

def capture_image():
    if do_image_capture:
        camera.capture(rawCapture, format='bgr', use_video_port=True)
        # do whatever you want on the captured data
        ...
        root.after(100, capture_image) # adjust the first argument to suit your case

capture_image()

下面的示例代碼正在使用線程:

import threading

stop_image_capture = False

def capture_image():
    for frame in camera.capture_continuous(rawCapture, format='bgr', use_video_port=True)
        # do whatever you want on the capture image
        ....
        if stop_image_capture:
            break

t = threading.Thread(target=capture_image)
t.setDaemon(True)
t.start()

暫無
暫無

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

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