Answers for "python access camera"

3

how to open webcam with python

import cv2

cap = cv2.VideoCapture(0)

# Check if the webcam is opened correctly
if not cap.isOpened():
    raise IOError("Cannot open webcam")

while True:
    ret, frame = cap.read()
    frame = cv2.resize(frame, None, fx=0.5, fy=0.5, interpolation=cv2.INTER_AREA)
    cv2.imshow('Input', frame)

    c = cv2.waitKey(1)
    if c == 27:
        break

cap.release()
cv2.destroyAllWindows()
Posted by: Guest on May-26-2020
1

accessing camera with python

import cv2

vid = cv2.VideoCapture(0)

while True:

    ret, frame = vid.read()

    cv2.imshow('Controlling my computer camera', frame)

    if cv2.waitKey(4) & 0xFF == ord('q'):
        break


vid.release()
cv2.destroyAllWindows()
Posted by: Guest on June-30-2021

Python Answers by Framework

Browse Popular Code Answers by Language