【发布时间】:2015-08-11 12:47:18
【问题描述】:
程序需要读取一个视频,计算帧数,然后显示在一个窗口中。该错误发生在视频结束后。 我该如何解决这个问题?
这里是来源:
import tkMessageBox
import cv2
banner = cv2.imread('../data/banner.png')
video = cv2.VideoCapture('../data/pintado_real_crop.avi')
contadorDeFrames = True
contador = 0
cv2.imshow('Projeto Pacu', banner)
cv2.moveWindow('Projeto Pacu', 100,50)
while(contadorDeFrames == True):
contadorDeFrames, frame = video.read()
contador = contador + 1
cv2.imshow("Video", frame)
cv2.moveWindow('Video', 100, 178)
print"Frame: %d" %contador
k = cv2.waitKey(30) & 0xff
if k == 27:
break
tkMessageBox.showinfo("Frames contador: %d" %contador)
video.release()
cv2.destroyAllWindows()
完全错误:
OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /build/buildd/opencv-2.4.8+dfsg1/modules/highgui/src/window.cpp, line 269
Traceback (most recent call last):
File "/home/vagner/PycharmProjects/TesteVideo/src/TestaVideo.py", line 20, in <module>
cv2.imshow("Video", frame)
cv2.error: /build/buildd/opencv-2.4.8+dfsg1/modules/highgui/src/window.cpp:269: error: (-215) size.width>0 && size.height>0 in function imshow
【问题讨论】:
-
一般是加载图片失败,或者图片为空。
-
在
video.read()之后直接添加if not contadorDeFrames: break or do whatever should happen after the video之类的东西 -
Micka 成功了,感谢您的帮助。