-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathalign_texts.py
More file actions
36 lines (28 loc) · 835 Bytes
/
align_texts.py
File metadata and controls
36 lines (28 loc) · 835 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import argparse
from pathlib import Path
import cv2
import imageio
import numpy as np
def main():
parser = argparse.ArgumentParser()
parser.add_argument("path")
args = parser.parse_args()
imgs = []
max_height = 0
img_paths = list(Path(args.path).glob("*.jpg"))
for img_path in img_paths:
img = imageio.imread(img_path.as_posix())
if len(img.shape) == 2:
img = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB)
imgs.append(img)
max_height = max(max_height, img.shape[0])
for img, img_path in zip(imgs, img_paths):
img = np.pad(
img,
[[0, max_height - img.shape[0]], [0, 0], [0, 0]],
mode="constant",
constant_values=255,
)
imageio.imwrite(img_path, img)
if __name__ == "__main__":
main()