-
Notifications
You must be signed in to change notification settings - Fork 50
/
comp.py
32 lines (22 loc) · 981 Bytes
/
comp.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
import os
import cv2
import numpy as np
from tqdm import tqdm
from options.options import Options
from utils.util import create_dir, get_file_list
if __name__ == '__main__':
opt = Options().parse_args()
create_dir(os.path.join(opt.src_dir, 'comp'))
foregrounds = get_file_list(os.path.join(opt.src_dir, 'images'), suffix='fake')
backgrounds = get_file_list(os.path.join(opt.tgt_dir, 'crop'))
masks = get_file_list(os.path.join(opt.tgt_dir, 'mask'))
for i in tqdm(range(len(foregrounds))):
fg = cv2.imread(foregrounds[i])
bg = cv2.imread(backgrounds[i + opt.offset])
mask = cv2.imread(masks[i + opt.offset])
mask = cv2.erode(mask, np.ones((3,3), np.uint8), iterations=9)
mask = cv2.GaussianBlur(mask, (5,5), cv2.BORDER_DEFAULT) / 255.0
comp = mask * fg + (1 - mask) * bg
cv2.imwrite(os.path.join(opt.src_dir, 'comp', '%05d.png' % (i+1)), comp)
if i >= opt.test_num:
break