Capture Video from Camera using OpenCV in Python

Python provides various libraries for image and video processing.

STEPS TO CAPTURE A VIDEO:

  • Use cv2. Video Capture() to get a video capture object for the camera
  • set up an infinite while loop and use the read()method to read the frames using the above created object
  • Use cv2.imshow() method to show the frames in the video.

Breaks the loop when the user clicks a specific key.

import cv2
vid = cv2.VideoCapture(0)
while(True):
         ret , frame = vid.read()
         cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0**FF == ord('q'):
         break
vid.release()
cv2.destroyAllWindows()

OUTPUT:

http://openCV video img

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top