"""Report the resolution each camera index actually delivers (default, and after requesting
higher resolutions), per backend. Diagnoses low-res capture (e.g. Continuity Camera ignoring
the resolution request). Usage: python probe_cameras.py"""
import cv2

backends = [("AVFOUNDATION", getattr(cv2, "CAP_AVFOUNDATION", cv2.CAP_ANY)), ("ANY", cv2.CAP_ANY)]
for idx in range(5):
    for bname, b in backends:
        cap = cv2.VideoCapture(idx, b)
        if not cap.isOpened():
            cap.release()
            continue
        ok, fr = cap.read()
        if not ok or fr is None:
            print(f"idx {idx:2d} [{bname:12s}]: opens but no frames")
            cap.release()
            continue
        default = f"{fr.shape[1]}x{fr.shape[0]}"
        got = []
        for w, h in [(3840, 2160), (1920, 1080), (1280, 720)]:
            cap.set(cv2.CAP_PROP_FRAME_WIDTH, w)
            cap.set(cv2.CAP_PROP_FRAME_HEIGHT, h)
            ok, fr = cap.read()
            got.append(f"req {w}x{h}->{fr.shape[1]}x{fr.shape[0]}" if ok and fr is not None else f"req {w}x{h}->none")
        print(f"idx {idx:2d} [{bname:12s}]: default {default:10s} | " + "  ".join(got))
        cap.release()
