This commit is contained in:
lda committed 2026-03-01 19:47:58 +07:00
1 parent 0cd543a21a
commit 61af362da5
6 files changed
+420 -14

No files matched your search

+53
View File
@@ -0,0 +1,53 @@
#!/usr/bin/env python
"""Quick utility to check available webcams and their properties."""
import sys
import cv2
def check_webcams(max_index: int = 5):
"""Probe webcam indices 0 to max_index and print their info."""
print("Scanning for webcams...\n")
found = []
for i in range(max_index):
cap = cv2.VideoCapture(i)
if cap.isOpened():
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
fps = cap.get(cv2.CAP_PROP_FPS)
backend = cap.getBackendName()
print(f"[{i}] ✓ FOUND")
print(f" Resolution: {width}x{height}")
print(f" FPS: {fps}")
print(f" Backend: {backend}")
# Try to read a frame to confirm it actually works
ret, frame = cap.read()
if ret:
print(f" Frame read: OK ({frame.shape})")
else:
print(" Frame read: FAILED (camera may be in use)")
found.append(i)
print()
cap.release()
if not found:
print("No webcams found!")
else:
print(f"Found {len(found)} webcam(s): {found}")
print(f"\nUsage: uv run main.py --source {found[0]}")
if __name__ == "__main__":
if len(sys.argv) >= 2:
try:
m = int(sys.argv[1])
except ValueError:
print(f"Usage: {sys.argv[0]} [MAX_INDEX: 5]")
else:
check_webcams(m)
else:
check_webcams()