Download scripts/test_camera.py from zhicao/i2rt: direct link, hf CLI and curl.
- Browser
- Download file 1.11 kB
-
https://huggingface.co/zhicao/i2rt/resolve/main/scripts/test_camera.py
- Command line
-
hf download hf://zhicao/i2rt/scripts/test_camera.py
-
curl -L -o test_camera.py https://huggingface.co/zhicao/i2rt/resolve/main/scripts/test_camera.py
1.11 kB
| """Show a live view from every connected camera. Press 'q' to quit.""" | |
| import glob | |
| import cv2 | |
| def find_working_cameras() -> list[str]: | |
| working = [] | |
| for path in sorted(glob.glob("/dev/video*")): | |
| cap = cv2.VideoCapture(path, cv2.CAP_V4L2) | |
| if cap.isOpened(): | |
| ok, frame = cap.read() | |
| if ok and frame is not None: | |
| working.append(path) | |
| cap.release() | |
| return working | |
| def main() -> None: | |
| devices = find_working_cameras() | |
| print(f"found {len(devices)} working camera(s): {devices}") | |
| if not devices: | |
| print("no working cameras found") | |
| return | |
| caps = {path: cv2.VideoCapture(path, cv2.CAP_V4L2) for path in devices} | |
| try: | |
| while True: | |
| for path, cap in caps.items(): | |
| ok, frame = cap.read() | |
| if ok: | |
| cv2.imshow(path, frame) | |
| if cv2.waitKey(1) & 0xFF == ord("q"): | |
| break | |
| finally: | |
| for cap in caps.values(): | |
| cap.release() | |
| cv2.destroyAllWindows() | |
| if __name__ == "__main__": | |
| main() | |