【问题标题】:Combining OpenCV, Python, Tkinter and PiCamera结合 OpenCV、Python、Tkinter 和 PiCamera
【发布时间】:2019-06-25 06:30:36
【问题描述】:

我在程序中使用 OpenCV、Python、Tkinter 和 PiCamera 时遇到问题。

  • Tkinter 窗口用于显示和设置要在 OpenCV 中使用的值:

  • 我正在尝试不断读取和处理我目前正在使用的 PiCamera 的视频源:

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

但是在互联网上阅读了一些内容后,我发现使用update() 是不可取的,所以我尝试了运气来理解线程,但我失败了。 VideoCapture() 有很多例子,它与 USB 相机一起使用,但与 PiCamera 一起使用的例子不多。除了穿线还有其他方法吗?

【问题讨论】:

标签: python opencv tkinter


【解决方案1】:

您可以使用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()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-08
    • 1970-01-01
    • 1970-01-01
    • 2017-10-11
    • 2015-05-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多