From b3ba9c13eeb6818a09b7e0ecc5212827205434ba Mon Sep 17 00:00:00 2001 From: zhouchengrong Date: Wed, 5 Feb 2025 17:12:28 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat=EF=BC=88=E6=96=B0=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=89:=20fix=EF=BC=88=E4=BF=AE=E5=A4=8Dbug=EF=BC=89:=20=20p?= =?UTF-8?q?rint=20overall=20=E6=97=8B=E8=BD=AC=E6=8A=A5=E9=94=99=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=20docs=EF=BC=88=E6=96=87=E6=A1=A3=E5=8F=98=E6=9B=B4?= =?UTF-8?q?=EF=BC=89:=20refactor=EF=BC=88=E9=87=8D=E6=9E=84=EF=BC=89:=20te?= =?UTF-8?q?st(=E5=A2=9E=E5=8A=A0=E6=B5=8B=E8=AF=95):?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/service/design_fast/pipeline/print_painting.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/service/design_fast/pipeline/print_painting.py b/app/service/design_fast/pipeline/print_painting.py index 6fe40d8..f03cdb1 100644 --- a/app/service/design_fast/pipeline/print_painting.py +++ b/app/service/design_fast/pipeline/print_painting.py @@ -442,8 +442,11 @@ class PrintPainting: angle: 旋转的角度 crop: 是否需要进行裁剪,布尔向量 """ + if not isinstance(crop, bool): + raise ValueError("The 'crop' parameter must be a boolean.") + crop_image = lambda img, x0, y0, w, h: img[y0:y0 + h, x0:x0 + w] - w, h = img.shape[:2] + h, w = img.shape[:2] # 旋转角度的周期是360° angle %= 360 # 计算仿射变换矩阵 @@ -455,7 +458,7 @@ class PrintPainting: if crop: # 裁剪角度的等效周期是180° angle_crop = angle % 180 - if angle > 90: + if angle_crop > 90: angle_crop = 180 - angle_crop # 转化角度为弧度 theta = angle_crop * np.pi / 180 From 9261e2cde694540ea3e4f9af07e9f42da4d62de9 Mon Sep 17 00:00:00 2001 From: zhouchengrong Date: Thu, 6 Feb 2025 16:22:43 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat=EF=BC=88=E6=96=B0=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=89:=20fix=EF=BC=88=E4=BF=AE=E5=A4=8Dbug=EF=BC=89:=20=20p?= =?UTF-8?q?rint=20overall=20=E6=97=8B=E8=BD=AC=E6=8A=A5=E9=94=99=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=20docs=EF=BC=88=E6=96=87=E6=A1=A3=E5=8F=98=E6=9B=B4?= =?UTF-8?q?=EF=BC=89:=20refactor=EF=BC=88=E9=87=8D=E6=9E=84=EF=BC=89:=20te?= =?UTF-8?q?st(=E5=A2=9E=E5=8A=A0=E6=B5=8B=E8=AF=95):?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/service/design_fast/pipeline/print_painting.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/service/design_fast/pipeline/print_painting.py b/app/service/design_fast/pipeline/print_painting.py index f03cdb1..6fe40d8 100644 --- a/app/service/design_fast/pipeline/print_painting.py +++ b/app/service/design_fast/pipeline/print_painting.py @@ -442,11 +442,8 @@ class PrintPainting: angle: 旋转的角度 crop: 是否需要进行裁剪,布尔向量 """ - if not isinstance(crop, bool): - raise ValueError("The 'crop' parameter must be a boolean.") - crop_image = lambda img, x0, y0, w, h: img[y0:y0 + h, x0:x0 + w] - h, w = img.shape[:2] + w, h = img.shape[:2] # 旋转角度的周期是360° angle %= 360 # 计算仿射变换矩阵 @@ -458,7 +455,7 @@ class PrintPainting: if crop: # 裁剪角度的等效周期是180° angle_crop = angle % 180 - if angle_crop > 90: + if angle > 90: angle_crop = 180 - angle_crop # 转化角度为弧度 theta = angle_crop * np.pi / 180 From bba91b46719b8ebd39680584912d46cd3e2019a9 Mon Sep 17 00:00:00 2001 From: zhouchengrong Date: Thu, 6 Feb 2025 17:42:02 +0800 Subject: [PATCH 3/4] =?UTF-8?q?feat=EF=BC=88=E6=96=B0=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=89:=20fix=EF=BC=88=E4=BF=AE=E5=A4=8Dbug=EF=BC=89:=20=20p?= =?UTF-8?q?rint=20=E4=BA=8E=20sketch=E6=8B=89=E4=BC=B8=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E7=9A=84print=E6=AF=94=E4=BE=8B=E4=B8=8D=E6=AD=A3=E7=A1=AE?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20docs=EF=BC=88=E6=96=87=E6=A1=A3=E5=8F=98?= =?UTF-8?q?=E6=9B=B4=EF=BC=89:=20refactor=EF=BC=88=E9=87=8D=E6=9E=84?= =?UTF-8?q?=EF=BC=89:=20test(=E5=A2=9E=E5=8A=A0=E6=B5=8B=E8=AF=95):?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/service/design_fast/pipeline/loading.py | 15 +++++++-- .../design_fast/pipeline/segmentation.py | 33 ++++++++++++++++--- app/service/design_fast/pipeline/split.py | 4 +-- app/service/utils/new_oss_client.py | 2 +- 4 files changed, 43 insertions(+), 11 deletions(-) diff --git a/app/service/design_fast/pipeline/loading.py b/app/service/design_fast/pipeline/loading.py index 5a55d9d..85d1fb1 100644 --- a/app/service/design_fast/pipeline/loading.py +++ b/app/service/design_fast/pipeline/loading.py @@ -1,9 +1,6 @@ -import io import logging import cv2 -import numpy as np -from PIL import Image from app.service.utils.new_oss_client import oss_get_image @@ -38,6 +35,18 @@ class LoadImage: def __call__(self, result): result['image'], result['pre_mask'] = self.read_image(result['path']) + + # 判断是否resize sketch 保留ori image 用于模型输入 + result['ori_image'] = result['image'] + if result['resize_scale'][0] != 0 and result['resize_scale'][1] != 0: + height, width = result['image'].shape[:2] + # 计算新的宽度和高度 + new_width = int(width * result['resize_scale'][0]) + new_height = int(height * result['resize_scale'][1]) + # 使用cv2.resize()函数进行缩放 + result['image'] = cv2.resize(result['image'], (new_width, new_height)) + if result['pre_mask'] is not None: + result['pre_mask'] = cv2.resize(result['pre_mask'], (new_width, new_height)) result['gray'] = cv2.cvtColor(result['image'], cv2.COLOR_BGR2GRAY) result['keypoint'] = self.get_keypoint(result['name']) result['img_shape'] = result['image'].shape diff --git a/app/service/design_fast/pipeline/segmentation.py b/app/service/design_fast/pipeline/segmentation.py index 0c9c51e..2ad1a57 100644 --- a/app/service/design_fast/pipeline/segmentation.py +++ b/app/service/design_fast/pipeline/segmentation.py @@ -36,12 +36,27 @@ class Segmentation: # preview 过模型 不缓存 if "preview_submit" in result.keys() and result['preview_submit'] == "preview": # 推理获得seg 结果 - seg_result = get_seg_result(result["image_id"], result['image']) + seg_result = get_seg_result(result["image_id"], result['ori_image']) + if result['resize_scale'][0] != 0 and result['resize_scale'][1] != 0: + height, width = seg_result.shape[:2] + # 计算新的宽度和高度 + new_width = int(width * result['resize_scale'][0]) + new_height = int(height * result['resize_scale'][1]) + # 使用cv2.resize()函数进行缩放 + seg_result = cv2.resize(seg_result, (new_width, new_height)) # submit 过模型 缓存 elif "preview_submit" in result.keys() and result['preview_submit'] == "submit": # 推理获得seg 结果 - seg_result = get_seg_result(result["image_id"], result['image']) - self.save_seg_result(seg_result, result['image_id']) + seg_result = get_seg_result(result["image_id"], result['ori_image']) + seg_result_save = seg_result + if result['resize_scale'][0] != 0 and result['resize_scale'][1] != 0: + height, width = seg_result.shape[:2] + # 计算新的宽度和高度 + new_width = int(width * result['resize_scale'][0]) + new_height = int(height * result['resize_scale'][1]) + # 使用cv2.resize()函数进行缩放 + seg_result = cv2.resize(seg_result, (new_width, new_height)) + self.save_seg_result(seg_result_save, result['image_id']) # null 正常流程 加载本地缓存 无缓存则过模型 else: # 本地查询seg 缓存是否存在 @@ -49,8 +64,16 @@ class Segmentation: # 判断缓存和实际图片size是否相同 if not _ or result["image"].shape[:2] != seg_result.shape: # 推理获得seg 结果 - seg_result = get_seg_result(result["image_id"], result['image']) - self.save_seg_result(seg_result, result['image_id']) + seg_result = get_seg_result(result["image_id"], result['ori_image']) + seg_result_save = seg_result + if result['resize_scale'][0] != 0 and result['resize_scale'][1] != 0: + height, width = seg_result.shape[:2] + # 计算新的宽度和高度 + new_width = int(width * result['resize_scale'][0]) + new_height = int(height * result['resize_scale'][1]) + # 使用cv2.resize()函数进行缩放 + seg_result = cv2.resize(seg_result, (new_width, new_height)) + self.save_seg_result(seg_result_save, result['image_id']) result['seg_result'] = seg_result # 处理前片后片 diff --git a/app/service/design_fast/pipeline/split.py b/app/service/design_fast/pipeline/split.py index 344c5c5..f3374a1 100644 --- a/app/service/design_fast/pipeline/split.py +++ b/app/service/design_fast/pipeline/split.py @@ -21,11 +21,11 @@ class Split(object): def __call__(self, result): try: - if result['name'] in ('outwear', 'dress', 'blouse', 'skirt', 'trousers', 'tops', 'bottoms','accessories'): + if result['name'] in ('outwear', 'dress', 'blouse', 'skirt', 'trousers', 'tops', 'bottoms', 'accessories'): front_mask = result['front_mask'] back_mask = result['back_mask'] rgba_image = rgb_to_rgba(result['final_image'], front_mask + back_mask) - new_size = (int(rgba_image.shape[1] * result["scale"] * result["resize_scale"][0]), int(rgba_image.shape[0] * result["scale"] * result["resize_scale"][1])) + new_size = (int(rgba_image.shape[1] * result["scale"]), int(rgba_image.shape[0] * result["scale"])) rgba_image = cv2.resize(rgba_image, new_size) result_front_image = np.zeros_like(rgba_image) front_mask = cv2.resize(front_mask, new_size) diff --git a/app/service/utils/new_oss_client.py b/app/service/utils/new_oss_client.py index 7939333..cf6f861 100644 --- a/app/service/utils/new_oss_client.py +++ b/app/service/utils/new_oss_client.py @@ -82,7 +82,7 @@ if __name__ == '__main__': # url = "aida-users/89/sketchboard/female/Dress/e6724ab7-8d3f-4677-abe0-c3e42ab7af85.jpeg" # url = "aida-users/87/print/956614a2-7e75-4fbe-9ed0-c1831e37a2c9-4-87.png" # url = "aida-users/89/single_logo/123-89.png" - url = "aida-users/89/123-89.png" + url = "aida-results/result_40e527bf-e46d-11ef-813d-0826ae3ad6b3.png" # url = "aida-collection-element/12148/Sketchboard/95ea577b-305b-4a62-b30a-39c0dd3ddb3f.png" read_type = "2" From eed0ac13a1547f25c74b44a9a213e26b3c39a107 Mon Sep 17 00:00:00 2001 From: zhouchengrong Date: Thu, 6 Feb 2025 17:42:24 +0800 Subject: [PATCH 4/4] =?UTF-8?q?feat=EF=BC=88=E6=96=B0=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=89:=20fix=EF=BC=88=E4=BF=AE=E5=A4=8Dbug=EF=BC=89:=20=20s?= =?UTF-8?q?ketch=E6=8B=89=E4=BC=B8=E5=AF=BC=E8=87=B4=E7=9A=84print?= =?UTF-8?q?=E6=AF=94=E4=BE=8B=E4=B8=8D=E6=AD=A3=E7=A1=AE=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20docs=EF=BC=88=E6=96=87=E6=A1=A3=E5=8F=98=E6=9B=B4=EF=BC=89:?= =?UTF-8?q?=20refactor=EF=BC=88=E9=87=8D=E6=9E=84=EF=BC=89:=20test(?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B5=8B=E8=AF=95):?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/service/design_fast/pipeline/print_painting.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/service/design_fast/pipeline/print_painting.py b/app/service/design_fast/pipeline/print_painting.py index 6fe40d8..f03cdb1 100644 --- a/app/service/design_fast/pipeline/print_painting.py +++ b/app/service/design_fast/pipeline/print_painting.py @@ -442,8 +442,11 @@ class PrintPainting: angle: 旋转的角度 crop: 是否需要进行裁剪,布尔向量 """ + if not isinstance(crop, bool): + raise ValueError("The 'crop' parameter must be a boolean.") + crop_image = lambda img, x0, y0, w, h: img[y0:y0 + h, x0:x0 + w] - w, h = img.shape[:2] + h, w = img.shape[:2] # 旋转角度的周期是360° angle %= 360 # 计算仿射变换矩阵 @@ -455,7 +458,7 @@ class PrintPainting: if crop: # 裁剪角度的等效周期是180° angle_crop = angle % 180 - if angle > 90: + if angle_crop > 90: angle_crop = 180 - angle_crop # 转化角度为弧度 theta = angle_crop * np.pi / 180