-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera.py
More file actions
33 lines (23 loc) · 717 Bytes
/
camera.py
File metadata and controls
33 lines (23 loc) · 717 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import cv2
def take_picture():
# Open the default camera (usually the built-in webcam)
cap = cv2.VideoCapture(0)
if not cap.isOpened():
print("Error: Unable to access the camera.")
return
print("Press 'q' to stop capturing.")
while True:
ret, frame = cap.read()
if not ret:
break
# Display the frame
cv2.imshow("Camera Feed", frame)
# Wait for 50 milliseconds (20 frames per second)
if cv2.waitKey(50) & 0xFF == ord('q'):
break
# Release the camera and video writer
cap.release()
cv2.destroyAllWindows()
return frame
if __name__ == "__main__":
take_picture()