【发布时间】:2015-07-15 14:46:04
【问题描述】:
我目前正在从事一个项目,其中包括在 gui 中显示视频。 该软件在树莓派上运行,并用 python 编写。我正在为 gui 使用 tkinter。
当我运行 playvideo 功能时,只显示最后一帧。 首先我认为覆盆子会变慢,但在插入 sleep(3) 之后也没有任何改变。
有人看到我的错误吗?
def play_video():
cap = cv2.VideoCapture('video.h264')
ret = True
while(ret):
ret, frame = cap.read()
time.sleep(3)
if ret:
print "in"
img = Image.fromarray(frame)
imgtk = ImageTk.PhotoImage(image=img)
show_video_label .imgtk = imgtk
show_video_label .configure(image=imgtk)
show_video_label._image_cache = imgtk
cap.release()
非常感谢!!!
【问题讨论】:
-
你最可能需要的是:在某处覆盖paint方法。现在发生的事情是,有一个线程正在绘制 UI。但是, play_video() 占用了整个线程 - 因此您最终只得到最后一帧。
标签: python opencv tkinter raspberry-pi