繁体   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