Files
traffic-monitoring-new/test_webcam.py
2025-07-16 19:36:56 +08:00

29 lines
508 B
Python

import cv2
# Open the default camera (0)
cap = cv2.VideoCapture(0)
if not cap.isOpened():
print("Error: Could not open webcam.")
exit()
print("Press 'q' to quit.")
while True:
ret, frame = cap.read()
if not ret:
print("Failed to grab frame")
break
# Display the resulting frame
cv2.imshow('Webcam Test', frame)
# Press 'q' to exit
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# Release everything when done
cap.release()
cv2.destroyAllWindows()