-
Notifications
You must be signed in to change notification settings - Fork 0
/
paste.py
36 lines (32 loc) · 1.11 KB
/
paste.py
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 os
import cv2
import numpy as np
from glob import glob
bg_paths = glob('bgs/*')
char_paths = glob('AlpChars/*') + glob('ProChars/*')
for char_path in char_paths:
char_img = cv2.imread(char_path, -1)
char = os.path.basename(char_path).split('.')[0]
save_dir = os.path.join('paste_img', char)
if not os.path.exists(save_dir):
os.mkdir(save_dir)
h, w, _ = char_img.shape
for bg_path in bg_paths:
color = 0
if 'blue' in bg_path or 'black' in bg_path:
color = 255
if char == '警':
if 'white' not in bg_path:
continue
color = [36, 27, 237]
if char == '学' and 'yellow' not in bg_path:
continue
if char in ['使', '领', '港', '澳']:
if 'black' not in bg_path:
continue
bg_img = cv2.imread(bg_path, -1)
bg_img = cv2.resize(bg_img, (w, h))
y, x = np.where(char_img[:, :, 3] > 200)
bg_img[y, x] = color
img_name = os.path.basename(bg_path).split('.')[0] + '.jpg'
cv2.imwrite(os.path.join(save_dir, img_name), bg_img)