Spaces:
Build error
Build error
Download app.py from ake178178/objectdetection202410: direct link, hf CLI and curl.
- Browser
- Download file 624 Bytes
-
https://huggingface.co/spaces/ake178178/objectdetection202410/resolve/main/app.py
- Command line
-
hf download hf://spaces/ake178178/objectdetection202410/app.py
-
curl -L -o app.py https://huggingface.co/spaces/ake178178/objectdetection202410/resolve/main/app.py
624 Bytes
| import cv2 | |
| # 打开默认摄像头,通常为0 | |
| cap = cv2.VideoCapture(0) | |
| # 检查摄像头是否成功打开 | |
| if not cap.isOpened(): | |
| print("无法打开摄像头") | |
| exit() | |
| # 读取并显示摄像头画面 | |
| while True: | |
| # 从摄像头读取一帧 | |
| ret, frame = cap.read() | |
| # 检查是否成功读取帧 | |
| if not ret: | |
| print("无法接收帧,结束程序") | |
| break | |
| # 显示帧 | |
| cv2.imshow('摄像头', frame) | |
| # 按下 'q' 键退出 | |
| if cv2.waitKey(1) & 0xFF == ord('q'): | |
| break | |
| # 释放摄像头并关闭所有窗口 | |
| cap.release() | |
| cv2.destroyAllWindows() |