[英]error: (-215) size.width>0 && size.height>0 in function imshow
The program needs to read a video, do the counting of frames and then show in a window. 该程序需要读取视频,对帧进行计数,然后在窗口中显示。 The error occurs after the video ends. 视频结束后发生错误。 How can i solve this? 我该如何解决?
Here is the source: 来源如下:
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()
Complete Error: 完成错误:
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
In your code, you are trying to print the null frame: 在您的代码中,您尝试打印空框架:
contadorDeFrames, frame = video.read()
contador = contador + 1
cv2.imshow("Video", frame)
when your code reads the frame which is last frame+1, the value will be null and you are trying to print that frame. 当您的代码读取最后一帧+1的帧时,该值将为null,并且您尝试打印该帧。 So check whether the frame is null or not and print. 因此,检查框架是否为空并打印。
I don´t have an answer for the question but i can specify from where the error came and i have a workaround. 我没有问题的答案,但是我可以指定错误的来源,并且有解决方法。
Like you see in my first example i tried to print a quit in the if statement and noticed that it doesnt get called. 就像您在我的第一个示例中看到的那样,我尝试在if语句中打印一个quit并注意到它没有被调用。 So i showed how much Frames the video had and let the if statement get called by the framenumbers. 所以我展示了视频有多少帧,并通过帧号调用if语句。 So the Error Disapear. 所以错误消失了。
Example 1: 范例1:
import numpy as np
import cv2
cap = cv2.VideoCapture('richtigcounter.mp4')
frames =1
while True:
ret, frame = cap.read()
print ("test")
cv2.imshow('frame',frame)
frames =frames + 1
print (frames)
if cv2.waitKey(1) & 0xFF == ord('q'):
print("Quit")
break
cap.release()
cv2.destroyWindow(cap)
Example 2: 范例2:
import numpy as np
import cv2
import time
def Reinfall():
cap = cv2.VideoCapture('reinfallcounter.mp4')
frames =1
while True:
ret, frame = cap.read()
cv2.imshow('video', frame)
frames =frames + 1
print (frames)
cv2.waitKey(1)
if frames == 245:
print("Quit")
break
cap.release()
cv2.destroyAllWindows()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.