我正在尝试将网络摄像头的最后 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 Frameworkrwork,你必须调用
cv2.waitKey(500)
定期,因为这是 OpenCv 的 Highgui 组件处理事件(并更新显示)的唯一方法。否则 highgui 只是“挂起”。
for image in image_list:
cv2.imshow("frame", image)
cv2.waitKey(500)
摘自docs :
Note
This function is the only method in HighGUI that can fetch and handle events, so it needs to be called periodically for normal event processing unless HighGUI is used within an environment that takes care of event processing.
关于python - 如何让 cv2.imshow() 显示列表中的帧?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59889892/