Spaces:
Runtime error
Runtime error
Download utils.py from innat/Google-MediaPipe: direct link, hf CLI and curl.
- Browser
- Download file 523 Bytes
-
https://huggingface.co/spaces/innat/Google-MediaPipe/resolve/main/utils.py
- Command line
-
hf download hf://spaces/innat/Google-MediaPipe/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/innat/Google-MediaPipe/resolve/main/utils.py
523 Bytes
| import cv2, math | |
| DESIRED_HEIGHT = 480 | |
| DESIRED_WIDTH = 480 | |
| def read_n_resize(image_file, read=True): | |
| image = cv2.imread(image_file) if read else image_file | |
| image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) if read else image | |
| h, w = image.shape[:2] | |
| if h < w: | |
| img = cv2.resize( | |
| image, (DESIRED_WIDTH, math.floor(h/(w/DESIRED_WIDTH))) | |
| ) | |
| else: | |
| img = cv2.resize( | |
| image, (math.floor(w/(h/DESIRED_HEIGHT)), DESIRED_HEIGHT) | |
| ) | |
| return img |