Python OpenCV: Capture video from camera

Python use libraries for image and video  processing. OpenCV is a library that helps in providing various functions for image and video operations. In this we can capture a video by the camera. Following are the steps:

  1. Import the OpenCV library:First we have to install OpenCV.
  2. Create a video capture object: Use cv.VideoCapture() to get a vide
  3. Set up an infinite loop: Inside a while loop, use the read() method to continuously read frames from the camera. This loop will keep capturing frames until you break out of it.
  4. Display the frames: Use cv.imshow() to display the frames in a window.
  5. Break the loop: To exit the loop, you can set a specific key as quitting button.
import cv
video=cv.VideoCapture(0)
while(True):
    ret, frame = video.read()
    cv.imshow('frame', frame)
    if cv.waitkey(1) & 0xFF == ord('q'):
        break
video.release()
cv.destroyAllWindows()

 

Leave a Comment

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

Scroll to Top