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)