I'm using openCv and python 2.7.
I'm trying to read a video but the last frame has no type and I can't show it.
My video has 16 frames and frame rate is 4fps.
Printing the types of the frames I get:
<type 'numpy.ndarray'>
<type 'numpy.ndarray'>
<type 'numpy.ndarray'>
...
<type 'numpy.ndarray'>
<type 'NoneType'>
OpenCV Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow, fi
le C:\builds\master_PackSlaveAddon-win64-vc12-static\opencv\modules\highgui\src\
window.cpp, line 271
Traceback (most recent call last):
File "3_1.py", line 113, in <module>
cv2.imshow('frame',frame)
cv2.error: C:\builds\master_PackSlaveAddon-win64-vc12-static\opencv\modules\high
gui\src\window.cpp:271: error: (-215) size.width>0 && size.height>0 in function
cv::imshow
My code is:
cap_2 = cv2.VideoCapture('video.avi')
while(cap_2.isOpened()):
ret, frame = cap_2.read()
print type(frame)
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap_2.release()
cv2.destroyAllWindows()
retto see whether the read succeeded, nor do you testframefor not being empty, before you pass it toimshow. Furthermore,VideoCapture::isOpened()returnsTrueas long as the video is open. Reading all the frames will not affect that. - Dan Mašek