Download Data/Rodin/2.py from slongle/3DEval: direct link, hf CLI and curl.
- Browser
- Download file 1.24 kB
-
https://huggingface.co/datasets/slongle/3DEval/resolve/main/Data/Rodin/2.py
- Command line
-
hf download hf://datasets/slongle/3DEval/Data/Rodin/2.py
-
curl -L -o 2.py https://huggingface.co/datasets/slongle/3DEval/resolve/main/Data/Rodin/2.py
1.24 kB
| import os | |
| import cv2 | |
| import numpy as np | |
| from tqdm import tqdm | |
| from PIL import Image, ImageDraw, ImageFont | |
| def add_text_to_image(image, text, position): | |
| # position: X, Y coordinates | |
| image = Image.fromarray(image) | |
| draw = ImageDraw.Draw(image) | |
| font = ImageFont.load_default(size=30) | |
| draw.text(position, text, (255, 255, 255), font=font) | |
| image = np.array(image) | |
| return image | |
| def make_grid(images, nrow=8): | |
| n = len(images) | |
| ncol = n // nrow | |
| assert n == nrow * ncol, f"n={n} is not divisible by nrow={nrow}" | |
| h, w, c = images[0].shape | |
| grid = np.zeros((h * nrow, w * ncol, c), dtype=np.uint8) | |
| for i in range(nrow): | |
| for j in range(ncol): | |
| grid[i * h : (i + 1) * h, j * w : (j + 1) * w] = images[i * ncol + j] | |
| return grid | |
| root_dir = "/ibex/user/dengj/3DEval/Data/Rodin/results-lowpack" | |
| n = 100 | |
| images = [] | |
| for i in tqdm(range(n)): | |
| filename = os.path.join(root_dir, f"{i}", "preview.webp") | |
| image = cv2.imread(filename) | |
| image = add_text_to_image(image, f"ID: {i}", (10, 10)) | |
| images.append(image) | |
| while len(images) % 10 != 0: | |
| images.append(np.ones_like(images[0]) * images[0].max()) | |
| image = make_grid(images, nrow=10) | |
| cv2.imwrite("result.png", image) | |