Add simple script to take an image with webcam and python
All checks were successful
/ test (push) Successful in 1m53s

This commit is contained in:
Aroy-Art 2024-02-23 12:25:11 +01:00
parent ed3274fe93
commit 725feb5d9a
Signed by: Aroy
GPG key ID: 583642324A1D2070

27
PythonScripts/webcam.py Normal file
View file

@ -0,0 +1,27 @@
import cv2
def take_picture(camera_index=0, file_name='captured_image.jpg'):
# Open a connection to the camera
cap = cv2.VideoCapture(camera_index)
if not cap.isOpened():
print("Error: Could not open camera.")
return
# Capture a single frame
ret, frame = cap.read()
if not ret:
print("Error: Could not capture a frame.")
cap.release()
return
# Save the captured frame to a file
cv2.imwrite(file_name, frame)
# Release the camera
cap.release()
print(f"Picture saved as {file_name}")
if __name__ == "__main__":
take_picture()