I need a link to auto take photo from cameras

Question:

Repl link:

import cv2

# Open the camera
cap = cv2.VideoCapture(0)

# Check if the camera is opened successfully
if not cap.isOpened():
    print("Error: Could not open camera")
    exit()

# Capture a frame from the camera
ret, frame = cap.read()

# Check if a frame is captured successfully
if not ret:
    print("Error: Could not capture frame")
    exit()

# Display the captured frame
cv2.imshow('Camera', frame)
cv2.waitKey(0)

# Save the captured frame as an image
cv2.imwrite('photo.jpg', frame)

# Release the camera and close the window
cap.release()
cv2.destroyAllWindows()
1 Like