AttributeError: 'NoneType' Object Has No Attribute 'copy'
The full error is : OpenCV: out device of bound (0-0): 1 OpenCV: camera failed to properly initialize! Traceback (most recent call last): File '/Users/syedrishad
Solution 1:
The line that causes the error:
imgResult = img.copy()
Making use of img
defined in the previous line:
success, img = cap.read()
The read
docs state:
The methods/functions combine VideoCapture::grab() and VideoCapture::retrieve() in one call. This is the most convenient method for reading video files or capturing data from decode and return the just grabbed frame. If no frames has been grabbed (camera has been disconnected, or there are no more frames in video file), the methods return false and the functions return NULL pointer.
So apparently img
is None
due to no data read.
Change to:
while True:
success, img = cap.read()
if img is None:
break
imgResult = img.copy()
Plus check what causes that no frames have been grabbed, either:
Baca Juga
- How To Import Word2vec Into Tensorflow Seq2seq Model?
- Pyqt5 Cannot Update Progress Bar From Thread And Received The Error "cannot Create Children For A Parent That Is In A Different Thread"
- Cannot Execute Custom Selenium Assert Function From User-extensions.js File, When Running Python Rc Against Selenium Server
- Camera has been disconnected (check all drivers to make sure it is installed and detected)
- There are no more frames in video file
Solution 2:
I guess you are trying to use the webcam. Please change the value to 0 as it's for using webcam. Have a nice day.
cap = cv2.VideoCapture(0)
Post a Comment for "AttributeError: 'NoneType' Object Has No Attribute 'copy'"