Spaces:
Sleeping
Sleeping
Download camera.py from TarSh8654/Mood_Identifier: direct link, hf CLI and curl.
- Browser
- Download file 712 Bytes
-
https://huggingface.co/spaces/TarSh8654/Mood_Identifier/resolve/main/camera.py
- Command line
-
hf download hf://spaces/TarSh8654/Mood_Identifier/camera.py
-
curl -L -o camera.py https://huggingface.co/spaces/TarSh8654/Mood_Identifier/resolve/main/camera.py
712 Bytes
| import cv2 as cv | |
| class Camera: | |
| def __init__(self): | |
| self.camera = cv.VideoCapture(0) | |
| if not self.camera.isOpened(): | |
| raise ValueError("Unable to open the camera!") | |
| # IMPORTANT: convert to int | |
| self.width = int(self.camera.get(cv.CAP_PROP_FRAME_WIDTH)) | |
| self.height = int(self.camera.get(cv.CAP_PROP_FRAME_HEIGHT)) | |
| def __del__(self): | |
| if self.camera.isOpened(): | |
| self.camera.release() | |
| def get_frame(self): | |
| if self.camera.isOpened(): | |
| ret, frame = self.camera.read() | |
| if ret: | |
| frame = cv.cvtColor(frame, cv.COLOR_BGR2RGB) | |
| return ret, frame | |
| return False, None | |