Spaces:
Runtime error
Runtime error
Download photowithcode.py from guney/photo-with-code: direct link, hf CLI and curl.
- Browser
- Download file 1.07 kB
-
https://huggingface.co/spaces/guney/photo-with-code/resolve/main/photowithcode.py
- Command line
-
hf download hf://spaces/guney/photo-with-code/photowithcode.py
-
curl -L -o photowithcode.py https://huggingface.co/spaces/guney/photo-with-code/resolve/main/photowithcode.py
1.07 kB
| from typing import List, Tuple | |
| import cv2 | |
| def dim_bg(im: cv2.Mat) -> cv2.Mat: | |
| im[..., 0] = im[..., 0] - im[..., 0].min() | |
| im[..., 1] = im[..., 1] - im[..., 1].min() | |
| im[..., 2] = im[..., 2] - im[..., 2].min() | |
| return im | |
| def mirror(im: cv2.Mat) -> cv2.Mat: | |
| im = cv2.flip(im, 1) | |
| return im | |
| def downscale_large_image(im1: cv2.Mat, im2: cv2.Mat) -> Tuple[cv2.Mat, cv2.Mat]: | |
| if im1.shape[0] > im2.shape[0]: | |
| return downscale_large_image(im2, im1) | |
| dim = (im1.shape[1], im1.shape[0]) | |
| im2 = cv2.resize(im2, dim, interpolation = cv2.INTER_AREA) | |
| return (im1, im2) | |
| def photowithcode_proc(photo: cv2.Mat, code: cv2.Mat, should_dim_bg: bool, should_mirror: bool) -> cv2.Mat: | |
| if should_dim_bg: | |
| print('dimming the background...') | |
| code = dim_bg(code) | |
| if should_mirror: | |
| print('mirroring code...') | |
| code = mirror(code) | |
| print('downscaling the larger image...') | |
| im1, im2 = downscale_large_image(photo, code) | |
| print('composing the image...') | |
| out = cv2.add(im1, im2) | |
| return out | |