Skip to content Skip to sidebar Skip to footer

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:

  1. Camera has been disconnected (check all drivers to make sure it is installed and detected)
  2. 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'"