Ask Your Question

Revision history [back]

openCV function '.read()' return (False, None)

import numpy as np import cv2

cap = cv2.VideoCapture(0)

while(True): ret, frame = cap.read() #frame = np.asarray(frame, dtype=np.uint8) frame = frame.astype('uint8') gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
    break

cap.release() cv2.destroyAllWindows()

Error as below : File "<ipython-input-18-f3066c3e32f2>", line 9, in <module> frame = frame.astype('uint8')

AttributeError: 'NoneType' object has no attribute 'astype'

click to hide/show revision 2
None

updated 2020-04-08 13:49:51 -0600

berak gravatar image

openCV function '.read()' return (False, None)

.

import numpy as np
import cv2

cv2

cap = cv2.VideoCapture(0)

cv2.VideoCapture(0)

while(True): ret, frame = cap.read() #frame = np.asarray(frame, dtype=np.uint8) frame = frame.astype('uint8') gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

cv2.COLOR_BGR2GRAY)
 cv2.imshow('frame',gray)
 if cv2.waitKey(1) & 0xFF == ord('q'):
     break

cap.release()
cv2.destroyAllWindows()

cap.release() cv2.destroyAllWindows()

Error as below : :

  File "<ipython-input-18-f3066c3e32f2>", line 9, in <module>
    frame = frame.astype('uint8')

frame.astype('uint8')

AttributeError: 'NoneType' object has no attribute 'astype'