Spaces:
Runtime error
Runtime error
Download scripts/data_augmentation.py from Steph254/piecefinder-backend: direct link, hf CLI and curl.
- Browser
- Download file 880 Bytes
-
https://huggingface.co/spaces/Steph254/piecefinder-backend/resolve/main/scripts/data_augmentation.py
- Command line
-
hf download hf://spaces/Steph254/piecefinder-backend/scripts/data_augmentation.py
-
curl -L -o data_augmentation.py https://huggingface.co/spaces/Steph254/piecefinder-backend/resolve/main/scripts/data_augmentation.py
880 Bytes
| import cv2 | |
| import numpy as np | |
| import os | |
| def generate_synthetic_puzzle(num_images: int, output_dir: str): | |
| os.makedirs(output_dir, exist_ok=True) | |
| for i in range(num_images): | |
| # Create blank image | |
| image = np.ones((1000, 1000, 3), dtype=np.uint8) * 255 | |
| # Add random puzzle pieces (simplified) | |
| for _ in range(np.random.randint(10, 50)): | |
| x = np.random.randint(100, 900) | |
| y = np.random.randint(100, 900) | |
| size = np.random.randint(50, 200) | |
| color = (np.random.randint(0, 256), np.random.randint(0, 256), np.random.randint(0, 256)) | |
| cv2.rectangle(image, (x, y), (x + size, y + size), color, -1) | |
| # Save image | |
| cv2.imwrite(os.path.join(output_dir, f'puzzle_{i}.jpg'), image) | |
| if __name__ == '__main__': | |
| generate_synthetic_puzzle(10, 'synthetic_puzzles') |