From 87fcd5e9e9c993f4896df9d6441cac1552b3e72b Mon Sep 17 00:00:00 2001 From: zhouchengrong Date: Mon, 22 Jul 2024 15:20:46 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=20=E5=A4=84=E7=90=86=E5=A4=9A=E5=B1=82s?= =?UTF-8?q?ketch=20design=E5=87=BA=E7=8E=B0=E7=9A=84=E5=86=85=E6=90=AD?= =?UTF-8?q?=E8=B6=8A=E7=95=8C=E9=97=AE=E9=A2=98=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/service/design/service.py | 2 +- app/service/design/utils/synthesis_item.py | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/service/design/service.py b/app/service/design/service.py index 03096ca..0200249 100644 --- a/app/service/design/service.py +++ b/app/service/design/service.py @@ -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'}) # 合成 - items_response['synthesis_url'] = synthesis(layers, body_size) + items_response['synthesis_url'] = synthesis(layers, body_size, basic_info) for lay in layers: items_response['layers'].append({ diff --git a/app/service/design/utils/synthesis_item.py b/app/service/design/utils/synthesis_item.py index 1b0c64f..d560f37 100644 --- a/app/service/design/utils/synthesis_item.py +++ b/app/service/design/utils/synthesis_item.py @@ -59,7 +59,7 @@ def positioning(all_mask_shape, mask_shape, offset): # @RunTime -def synthesis(data, size): +def synthesis(data, size, basic_info): # 创建底图 base_image = Image.new('RGBA', size, (0, 0, 0, 0)) try: @@ -68,9 +68,13 @@ def synthesis(data, size): body_mask = None for d in data: if d['name'] == 'body': - body_mask = d['image'].split()[3] - top_outer_mask = np.array(body_mask) - bottom_outer_mask = np.array(body_mask) + 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'] + 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 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_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"]: bottom = False 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_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: break