Spaces:
Sleeping
Sleeping
Download src/camera.py from Ephab/Hand_Digit_Recognition: direct link, hf CLI and curl.
- Browser
- Download file 500 Bytes
-
https://huggingface.co/spaces/Ephab/Hand_Digit_Recognition/resolve/main/src/camera.py
- Command line
-
hf download hf://spaces/Ephab/Hand_Digit_Recognition/src/camera.py
-
curl -L -o camera.py https://huggingface.co/spaces/Ephab/Hand_Digit_Recognition/resolve/main/src/camera.py
500 Bytes
| import cv2 as cv | |
| def frame_capture(): | |
| cam = cv.VideoCapture(0) | |
| if not cam.isOpened(): | |
| raise Exception("Camera couldn't open") | |
| try: | |
| while True: | |
| ret, frame = cam.read() | |
| if not ret: | |
| raise Exception("Frame couldn't be read for some reason") | |
| rgb_frame = cv.cvtColor(frame, cv.COLOR_BGR2RGB) | |
| yield {"bgr":frame, "rgb":rgb_frame} | |
| finally: | |
| cam.release() | |
| cv.destroyAllWindows() |