Friday , June 18 2021
Home / Computer Vision / Access Camera Using OpenCV with Python

Access Camera Using OpenCV with Python

11 Open Webcam

Access Camera Using OpenCV with Python

  • first, we Import libraries OpenCV.
  • Then we use VideoCapture(0) function to capture the feed of the webcam, here 0 indicates the default value of webcam. If you have secondary webcam use 1 instead of 0
  • Now read the frame of the camera frame by frame
  • ret is a boolean variable that checks if the camera is on or not
  • the frame is a variable in which all the camera feed is being saved
In [2]:
import cv2
capture=cv2.VideoCapture(0)
while True:
    ret,frame=capture.read()
    cv2.imshow('Color',frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
capture.release()
cv2.destroyAllWindows()

Save Image from Webcam

In [3]:
import cv2
capture=cv2.VideoCapture(0)
while True:
    ret,frame=capture.read()
    cv2.imshow('Color',frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        cv2.imwrite("MachineLearning.jpg",frame)
        break
capture.release()
cv2.destroyAllWindows()

About Machine Learning

Check Also

Record Video From a Webcam using OpenCV

12 Record Video using OpenCV Record Video From a Webcam using OpenCV¶ cv2.VideoWriter( filename, fourcc, …

Leave a Reply

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