I am a begginer in OpenCV and Python. I tried to load a video and displaying it using code given below:
import cv2
cap = cv2.VideoCapture('G:\3d scanner\2.mmv')
while(1):
_ , img2=cap.read()
cv2.namedWindow('video',cv2.WINDOW_NORMAL)
cv2.imshow('video',img2)
k=cv2.waitKey(1) & 0xFF
if k==27:
break
cap.release()
cv2.destroyAllWindows()
But it showing the following error:
OpenCV Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow, file ..\..\..\..\opencv\modules\highgui\src\window.cpp, line 261
File "test3.py", line 8, in <module>
cv2.imshow('video',img2)
cv2.error: ..\..\..\..\opencv\modules\highgui\src\window.cpp:261: error: (-215) size.width>0 && size.height>0 in function cv::imshow
There are previous questions on this site regarding this issue but the answers given were using cv library but not cv2.
Any idea of what is wrong in this?
img2 is None. could be due to various reasons. impossible to say which. official docs show you how to handle errors. the piece of code presented in the question lacks all error checking, even dismissing information that the user is explicitly told to handle. this very same question used to be asked all the time, but now it seems that useful Q&A pairs on this issue exist, which give people the solution rather than making them ask these questions anew every time.