繁体   English   中英

如何让 cv2.imshow() 显示列表中的帧?

[英]How to get cv2.imshow() to show frames from a list?

我正在尝试将网络摄像头的最后 50 帧保存到列表中,然后播放这些帧。 当我尝试显示框架时,显示窗口显示为灰色并表示它没有响应。 如果我在 while 循环中显示框架,它会显示,但如果我尝试显示列表中的框架,我将它们保存在上述问题中。 这是我正在运行的代码。

cap = cv2.VideoCapture(0)
image_list = []
count = 0
while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()

    image_list.append(frame)

    #Display the resulting frame
    #cv2.imshow('frame',frame)   <---  this will show me my live frame by frame capture

    if count >= 50:
        break

    count += 1

# When everything is done, release the capture
cap.release()

for image in image_list:  
    cv2.imshow("frame", image)
    sleep(1)

如果您不使用像 tkinter 或 Qt 这样的合适的 UI Framerwork,则必须调用

cv2.waitKey(500)

定期,因为它是 OpenCv 的 Highgui 组件处理事件(和更新显示)的唯一方法。 否则,highgui 只会“挂断”。

for image in image_list:  
    cv2.imshow("frame", image)
    cv2.waitKey(500)

文档摘录:

笔记

此函数是 HighGUI 中唯一可以获取和处理事件的方法,因此需要定期调用它以进行正常的事件处理,除非在负责事件处理的环境中使用 HighGUI。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM