feat 结果图宽度自适应
fix
This commit is contained in:
@@ -63,14 +63,18 @@ def synthesis(data, size, basic_info):
|
||||
# 创建底图
|
||||
base_image = Image.new('RGBA', size, (0, 0, 0, 0))
|
||||
try:
|
||||
|
||||
all_mask_shape = (size[1], size[0])
|
||||
body_mask = None
|
||||
for d in data:
|
||||
if d['name'] == 'body':
|
||||
body_mask = np.array(d['image'].split()[3])
|
||||
left_shoulder = basic_info['body_point_test']['shoulder_left']
|
||||
right_shoulder = basic_info['body_point_test']['shoulder_right']
|
||||
# 创建一个新的宽高透明图像, 把模特贴上去获取mask
|
||||
transparent_image = Image.new("RGBA", size, (0, 0, 0, 0))
|
||||
transparent_image.paste(d['image'], d['position'], d['image'])
|
||||
body_mask = np.array(transparent_image.split()[3])
|
||||
|
||||
# 根据新的坐标获取新的肩点
|
||||
left_shoulder = [x + y for x, y in zip(basic_info['body_point_test']['shoulder_left'], d['position'])]
|
||||
right_shoulder = [x + y for x, y in zip(basic_info['body_point_test']['shoulder_right'], d['position'])]
|
||||
body_mask[:min(left_shoulder[1], right_shoulder[1]), left_shoulder[0]:right_shoulder[0]] = 255
|
||||
_, binary_body_mask = cv2.threshold(body_mask, 127, 255, cv2.THRESH_BINARY)
|
||||
top_outer_mask = np.array(binary_body_mask)
|
||||
@@ -114,13 +118,13 @@ def synthesis(data, size, basic_info):
|
||||
if layer['image'] is not None:
|
||||
if layer['name'] != "body":
|
||||
test_image = Image.new('RGBA', size, (0, 0, 0, 0))
|
||||
test_image.paste(layer['image'], (layer['position'][1], layer['position'][0]), layer['image'])
|
||||
test_image.paste(layer['image'], layer['position'], layer['image'])
|
||||
mask_data = np.where(all_mask > 0, 255, 0).astype(np.uint8)
|
||||
mask_alpha = Image.fromarray(mask_data)
|
||||
cropped_image = Image.composite(test_image, Image.new("RGBA", test_image.size, (255, 255, 255, 0)), mask_alpha)
|
||||
base_image.paste(test_image, (0, 0), cropped_image)
|
||||
else:
|
||||
base_image.paste(layer['image'], (layer['position'][1], layer['position'][0]), layer['image'])
|
||||
base_image.paste(layer['image'], layer['position'], layer['image'])
|
||||
|
||||
result_image = base_image
|
||||
|
||||
|
||||
Reference in New Issue
Block a user