feat 处理多层sketch design出现的内搭越界问题
fix
This commit is contained in:
@@ -99,7 +99,7 @@ def process_object(cfg, process_id, total):
|
|||||||
uploaded_images.append({'image_obj': layer['mask'], 'image_url': layer['mask_url'], 'image_type': 'mask'})
|
uploaded_images.append({'image_obj': layer['mask'], 'image_url': layer['mask_url'], 'image_type': 'mask'})
|
||||||
|
|
||||||
# 合成
|
# 合成
|
||||||
items_response['synthesis_url'] = synthesis(layers, body_size)
|
items_response['synthesis_url'] = synthesis(layers, body_size, basic_info)
|
||||||
|
|
||||||
for lay in layers:
|
for lay in layers:
|
||||||
items_response['layers'].append({
|
items_response['layers'].append({
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ def positioning(all_mask_shape, mask_shape, offset):
|
|||||||
|
|
||||||
|
|
||||||
# @RunTime
|
# @RunTime
|
||||||
def synthesis(data, size):
|
def synthesis(data, size, basic_info):
|
||||||
# 创建底图
|
# 创建底图
|
||||||
base_image = Image.new('RGBA', size, (0, 0, 0, 0))
|
base_image = Image.new('RGBA', size, (0, 0, 0, 0))
|
||||||
try:
|
try:
|
||||||
@@ -68,9 +68,13 @@ def synthesis(data, size):
|
|||||||
body_mask = None
|
body_mask = None
|
||||||
for d in data:
|
for d in data:
|
||||||
if d['name'] == 'body':
|
if d['name'] == 'body':
|
||||||
body_mask = d['image'].split()[3]
|
body_mask = np.array(d['image'].split()[3])
|
||||||
top_outer_mask = np.array(body_mask)
|
left_shoulder = basic_info['body_point_test']['shoulder_left']
|
||||||
bottom_outer_mask = np.array(body_mask)
|
right_shoulder = basic_info['body_point_test']['shoulder_right']
|
||||||
|
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)
|
||||||
|
bottom_outer_mask = np.array(binary_body_mask)
|
||||||
|
|
||||||
top = True
|
top = True
|
||||||
bottom = True
|
bottom = True
|
||||||
@@ -85,7 +89,10 @@ def synthesis(data, size):
|
|||||||
all_y_start, all_y_end, mask_y_start, mask_y_end = positioning(all_mask_shape=all_mask_shape[0], mask_shape=mask_shape[0], offset=y_offset)
|
all_y_start, all_y_end, mask_y_start, mask_y_end = positioning(all_mask_shape=all_mask_shape[0], mask_shape=mask_shape[0], offset=y_offset)
|
||||||
all_x_start, all_x_end, mask_x_start, mask_x_end = positioning(all_mask_shape=all_mask_shape[1], mask_shape=mask_shape[1], offset=x_offset)
|
all_x_start, all_x_end, mask_x_start, mask_x_end = positioning(all_mask_shape=all_mask_shape[1], mask_shape=mask_shape[1], offset=x_offset)
|
||||||
# 将叠加区域赋值为相应的像素值
|
# 将叠加区域赋值为相应的像素值
|
||||||
top_outer_mask[all_y_start:all_y_end, all_x_start:all_x_end] = data[i]['mask'][mask_y_start:mask_y_end, mask_x_start:mask_x_end]
|
_, sketch_mask = cv2.threshold(data[i]['mask'], 127, 255, cv2.THRESH_BINARY)
|
||||||
|
background = np.zeros_like(top_outer_mask)
|
||||||
|
background[all_y_start:all_y_end, all_x_start:all_x_end] = sketch_mask[mask_y_start:mask_y_end, mask_x_start:mask_x_end]
|
||||||
|
top_outer_mask = background + top_outer_mask
|
||||||
elif bottom and data[i]['name'] in ["trousers_front", "skirt_front", "bottoms_front"]:
|
elif bottom and data[i]['name'] in ["trousers_front", "skirt_front", "bottoms_front"]:
|
||||||
bottom = False
|
bottom = False
|
||||||
mask_shape = data[i]['mask'].shape
|
mask_shape = data[i]['mask'].shape
|
||||||
@@ -94,7 +101,10 @@ def synthesis(data, size):
|
|||||||
all_y_start, all_y_end, mask_y_start, mask_y_end = positioning(all_mask_shape=all_mask_shape[0], mask_shape=mask_shape[0], offset=y_offset)
|
all_y_start, all_y_end, mask_y_start, mask_y_end = positioning(all_mask_shape=all_mask_shape[0], mask_shape=mask_shape[0], offset=y_offset)
|
||||||
all_x_start, all_x_end, mask_x_start, mask_x_end = positioning(all_mask_shape=all_mask_shape[1], mask_shape=mask_shape[1], offset=x_offset)
|
all_x_start, all_x_end, mask_x_start, mask_x_end = positioning(all_mask_shape=all_mask_shape[1], mask_shape=mask_shape[1], offset=x_offset)
|
||||||
# 将叠加区域赋值为相应的像素值
|
# 将叠加区域赋值为相应的像素值
|
||||||
bottom_outer_mask[all_y_start:all_y_end, all_x_start:all_x_end] = data[i]['mask'][mask_y_start:mask_y_end, mask_x_start:mask_x_end]
|
_, sketch_mask = cv2.threshold(data[i]['mask'], 127, 255, cv2.THRESH_BINARY)
|
||||||
|
background = np.zeros_like(top_outer_mask)
|
||||||
|
background[all_y_start:all_y_end, all_x_start:all_x_end] = sketch_mask[mask_y_start:mask_y_end, mask_x_start:mask_x_end]
|
||||||
|
bottom_outer_mask = background + bottom_outer_mask
|
||||||
elif bottom is False and top is False:
|
elif bottom is False and top is False:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user