Spaces:
Runtime error
Runtime error
Download utils.py from dongxiat/anycoder-d9e6aa28: direct link, hf CLI and curl.
- Browser
- Download file 802 Bytes
-
https://huggingface.co/spaces/dongxiat/anycoder-d9e6aa28/resolve/main/utils.py
- Command line
-
hf download hf://spaces/dongxiat/anycoder-d9e6aa28/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/dongxiat/anycoder-d9e6aa28/resolve/main/utils.py
802 Bytes
| import cv2 | |
| import numpy as np | |
| from PIL import Image | |
| def preprocess_image(image): | |
| """Preprocess image for text erasing""" | |
| # Convert to RGB if needed | |
| if image.mode != "RGB": | |
| image = image.convert("RGB") | |
| return image | |
| def create_text_mask(image_size, num_regions=5): | |
| """Create a simulated text mask for demonstration""" | |
| mask = np.zeros(image_size, dtype=np.uint8) | |
| for _ in range(num_regions): | |
| # Random position for text-like region | |
| x = np.random.randint(0, image_size[1] - 100) | |
| y = np.random.randint(0, image_size[0] - 30) | |
| width = np.random.randint(50, 200) | |
| height = np.random.randint(20, 40) | |
| # Draw rectangle (simulating text) | |
| cv2.rectangle(mask, (x, y), (x + width, y + height), 255, -1) | |
| return mask |