【发布时间】:2019-02-24 15:57:40
【问题描述】:
我想使用 python 在 openCV 中播放视频并随时关闭该窗口,但它不起作用。
import numpy as np
import cv2
fileName='test.mp4' # change the file name if needed
cap = cv2.VideoCapture(fileName) # load the video
while(cap.isOpened()):
# play the video by reading frame by frame
ret, frame = cap.read()
if ret==True:
# optional: do some image processing here
cv2.imshow('frame',frame) # show the video
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
cv2.waitKey(1)
cv2.destroyAllWindows()
cv2.waitKey(1)
窗口打开并开始播放视频,但我无法关闭窗口。
【问题讨论】:
-
您能否详细说明您的代码“不起作用”的原因?你期待什么,实际发生了什么?如果您遇到异常/错误,请发布它发生的行和异常/错误详细信息。请edit这些详细信息,否则我们可能无法提供帮助。
-
@PatrickArtner 我进行了编辑。谢谢
-
“我无法关闭窗口” .. 在什么意义上?对按键没有反应? (如果是这样,当您击键时窗口是否聚焦?)
-
@DanMašek 每次我单击窗口顶部的红十字关闭窗口时,它都会消失,但随后又会弹出。
标签: python python-3.x opencv