Spaces:
Running
on
Zero
Running
on
Zero
File size: 1,282 Bytes
adf1965 |
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 37 38 39 40 41 |
import os
import cv2
import numpy as np
from PIL import Image
# εζ―ββηεΌ
path1 = "/home/sd/Harddisk/zjh/Dataset/test/image"
# εζ―ββηζ
path2 = "/home/sd/Harddisk/zjh/CAT8/results50/P-GP2D"
# pair.txt
dataset_file = "/home/sd/Harddisk/zjh/Dataset/test_pairs.txt"
dataset_list = []
with open(dataset_file, 'r') as f:
for line in f.readlines():
name, _ = line.strip().split()
dataset_list.append(name)
os.makedirs("/home/sd/Harddisk/zjh/CAT8/results50/P-GP2P")
for i in range(len(dataset_list)):
name = dataset_list[i]
# mask θ·―εΎ
mask_path = os.path.join("/home/sd/Harddisk/zjh/Dataset/test/mask", name[:-4]+".png")
# εζ―θ·―εΎ
src_path = os.path.join(path1, name)
# εζ―θ·―εΎ
dst_path = os.path.join(path2, str(i)+".png")
# ε θ½½εζ―
src = cv2.imread(src_path)
src = cv2.resize(src, (384, 512))
# ε θ½½εζ―
dst = cv2.imread(dst_path)
# ε θ½½ mask
mask = Image.open(mask_path).convert("L").resize((384, 512))
mask = np.array(mask)
mask = 255-mask
# θε
output = cv2.seamlessClone(src, dst, mask, (192,256), cv2.NORMAL_CLONE)
# δΏε
cv2.imwrite(os.path.join("/home/sd/Harddisk/zjh/CAT8/results50/P-GP2P", name.replace("jpg", "png")), output)
|