From 58bc68ff5e1b94f07c6a6e0728bf802f653e3625 Mon Sep 17 00:00:00 2001 From: zhouchengrong Date: Thu, 1 Aug 2024 10:08:25 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=20=20design=20=E9=A2=84=E5=A4=84?= =?UTF-8?q?=E7=90=86=E6=96=B0=E5=A2=9Epadding=20=E5=A4=84=E7=90=86=20?= =?UTF-8?q?=E4=BD=BF=E5=9B=BE=E7=89=87=E4=B8=8D=E8=A6=81=E5=AE=8C=E5=85=A8?= =?UTF-8?q?=E8=B4=B4=E8=BE=B9=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/service/design_pre_processing/service.py | 34 +++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/app/service/design_pre_processing/service.py b/app/service/design_pre_processing/service.py index b6d868d..bd6f81c 100644 --- a/app/service/design_pre_processing/service.py +++ b/app/service/design_pre_processing/service.py @@ -60,6 +60,7 @@ class DesignPreprocessing: def bounding_box(self, image_list): for item in image_list: image = item['image_obj'] + height, width = image.shape[:2] # 使用Canny边缘检测来检测物体的轮廓 edges = cv2.Canny(image, 50, 150) # 查找轮廓 @@ -83,16 +84,25 @@ class DesignPreprocessing: if len(contours) > 0: cropped_image = image[y_min:y_max, x_min:x_max] item['obj'] = cropped_image # 新shape图像 - # 取消直接覆盖,新增size判断 - # try: - # # 覆盖到minio - # image_bytes = cv2.imencode(".jpg", cropped_image)[1].tobytes() - # self.minio_client.put_object(item['image_url'].split("/", 1)[0], item['image_url'].split("/", 1)[1], io.BytesIO(image_bytes), len(image_bytes), content_type="image/jpeg", ) - # print(f"Object '{item['image_url'].split('/', 1)[1]}' overwritten successfully.") - # except ResponseError as err: - # print(f"Error: {err}") else: item['obj'] = image + + padding_top = max(20 - y_min, 0) + padding_bottom = max(20 - (height - y_max), 0) + padding_left = max(20 - x_min, 0) + padding_right = max(20 - (width - x_max), 0) + + # 添加padding + padded_image = cv2.copyMakeBorder( + image, + padding_top, + padding_bottom, + padding_left, + padding_right, + cv2.BORDER_CONSTANT, + value=(255, 255, 255) # 你可以选择填充颜色,例如黑色 + ) + item['obj'] = padded_image return image_list def super_resolution(self, image_list): @@ -334,7 +344,7 @@ class DesignPreprocessing: ] try: # connections.connect(alias=MILVUS_ALIAS, host=MILVUS_DB_HOST, port=MILVUS_PORT) - start_time = time.time() + # start_time = time.time() # collection = Collection(MILVUS_TABLE_KEYPOINT) # Get an existing collection. # mr = collection.upsert(data) # logging.info(f"save keypoint time : {time.time() - start_time}") @@ -348,9 +358,9 @@ if __name__ == '__main__': data = { "sketches": [ { - "image_category": "dress", - "image_id": "107903", - "image_url": "aida-sys-image/images/female/dress/0628000000.jpg" + "image_category": "blouse", + "image_id": "123123123", + "image_url": "test/0628000198.jpg" } ] }