How do I access my webcam in Python?

前端 未结 4 1245
孤独总比滥情好
孤独总比滥情好 2020-12-02 06:09

I would like to access my webcam from Python.

I tried using the VideoCapture extension (tutorial), but that didn\'t work very well for me, I had to work around some

4条回答
  •  悲哀的现实
    2020-12-02 06:32

    import cv2 as cv
    
    capture = cv.VideoCapture(0)
    
    while True:
        isTrue,frame = capture.read()
        cv.imshow('Video',frame)
        if cv.waitKey(20) & 0xFF==ord('d'):
            break
    
    capture.release()
    cv.destroyAllWindows()
    

    0 <-- refers to the camera , replace it with file path to read a video file

    cv.waitKey(20) & 0xFF==ord('d') <-- to destroy window when key is pressed

提交回复
热议问题