-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathcam.py
More file actions
29 lines (23 loc) · 658 Bytes
/
cam.py
File metadata and controls
29 lines (23 loc) · 658 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
import cv2
def main():
# Initialize the webcam (0 is usually the default camera)
cap = cv2.VideoCapture(0)
if not cap.isOpened():
print("Cannot open camera")
return
while True:
# Capture frame-by-frame
ret, frame = cap.read()
if not ret:
print("Failed to grab frame")
break
# Display the resulting frame
cv2.imshow("Webcam", frame)
# Press 'q' to exit
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
if __name__ == "__main__":
main()