Capture Video Frame from Webcam in Python OpenCV

It is easy to capture video frame from webcam in python opencv. In this tutorial, we will use an example to show you how to capture.

Best Practice to Capture Video Frame from Webcam in Python OpenCV

1.Open webcam using opencv

import cv2

capture = cv2.VideoCapture(0)

2.Use capture.read() to capture video frame

while(True):
    ret, frame = capture.read()
    
    cv2.imshow('video', frame)
    
    if cv2.waitKey(1) == 27:
        break

3.Release webcam

capture.release()
cv2.destroyAllWindows()

Capture Video Frame from Webcam in Python OpenCV