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

asked 2020-04-08 12:50:02 -0600

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

berak gravatar image

.

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'

edit retag flag offensive close merge delete