AttributeError: 'NoneType' object has no attribute 'shape'
Hi all! I need your help regarding the following code. My goal is to read and show the video with a resolution modification.
After executing the above code, the video displayed on my screen till the end. However, I have got the following error:import cv2
cap = cv2.VideoCapture("C:/Users/user/Desktop/Foot_Detection/ball_tracking_example.mp4")
def rescale_frame(frame, percent=30): width = int(frame.shape[1] * percent/ 100) height = int(frame.shape[0] * percent/ 100) dim = (width, height) return cv2.resize(frame, dim, interpolation =cv2.INTER_AREA)
if (cap.isOpened() == False): print("Error opening video stream or file")
while (cap.isOpened()): # Capture frame-by-frame ret, frame = cap.read()
frame = rescale_frame(frame, percent=30) if ret == True:
cv2.imshow('Frame', frame)
if cv2.waitKey(25) & 0xFF == ord('q'): break
else: break
cap.release()
cv2.destroyAllWindows()
Traceback (most recent call last):
File "C:/Users/user/Desktop/Foot_Detection/FootDetection.py", line 24, in <module>
frame = rescale_frame(frame, percent=30)
File "C:/Users/user/Desktop/Foot_Detection/FootDetection.py", line 10, in rescale_frame
width = int(frame.shape[1] * percent/ 100)
AttributeError: 'NoneType' object has no attribute 'shape'
I tried to install the codec for mp4 and to the video path is correct. Could you please assist me in this matter? Thank you in advance.
checking the
ret
value ismandatory
, since it will tell you, when the movie's over.Nope, berak. What does the error tell you? AttributeError: 'NoneType' object has no attribute 'shape'
again, the last frame will be empty (None)
(and this is one of the main differences between capturing from a webcam or a video file, please go and check)
Nope. The frame is not empty. I already tested it.. There are no differences between webcam and file.
@Abdu, can you take another look at the code in your question, and try to repair the broken formatting ?
(whitespace matters in python ...)