mardi 14 juillet 2020

AttributeError: 'NoneType' object has no attribute 'read' Video Record + python selenium

I'm new to Python. My TL gives me a project that automates screenshot and video recording. I already manage to create and successfully run the screenshot, however, in video recording I encountered this error "AttributeError: 'NoneType' object has no attribute 'read'" and I already searched in google but I can't find an answer or how to do it. Anyone can help me with this problem? Thanks. below is my code

import cv2
import numpy as np

cam = cv2.VideoCapture(0).release()
fourcc = cv2.VideoWriter_fourcc(*"MJPG")
rec = cv2.VideoWriter("output.avi", fourcc,1,(640,480))


while True:
    b, img = cam.read()
enter code here`   cv2.imshow("Screen Record",img)
    rec.write(img)
    key = cv2.waitKey(1)&0xFF
    if key == ord('q'):
        rec.release()
        break
cam.release()
cam.destroyAllWindows()

Aucun commentaire:

Enregistrer un commentaire