feat(新功能):
fix(修复bug): accessories 替换为 others docs(文档变更): refactor(重构): test(增加测试):
This commit is contained in:
@@ -6,8 +6,8 @@ import requests
|
||||
from minio import Minio
|
||||
|
||||
from app.core.config import *
|
||||
from app.service.design_fast.item import BodyItem, TopItem, BottomItem, AccessoriesItem
|
||||
from app.service.design_fast.utils.organize import organize_body, organize_clothing, organize_accessories
|
||||
from app.service.design_fast.item import BodyItem, TopItem, BottomItem, OthersItem
|
||||
from app.service.design_fast.utils.organize import organize_body, organize_clothing, organize_others
|
||||
from app.service.design_fast.utils.progress import final_progress, update_progress
|
||||
from app.service.design_fast.utils.synthesis_item import synthesis, synthesis_single, update_base_size_priority
|
||||
from app.service.utils.decorator import RunTime
|
||||
@@ -30,8 +30,8 @@ def process_item(item, basic):
|
||||
elif item['type'].lower() in ['skirt', 'trousers', 'bottoms']:
|
||||
bottom_server = BottomItem(data=item, basic=basic, minio_client=minio_client)
|
||||
item_data = bottom_server.process()
|
||||
elif item['type'].lower() in ['accessories']:
|
||||
bottom_server = AccessoriesItem(data=item, basic=basic, minio_client=minio_client)
|
||||
elif item['type'].lower() in ['others']:
|
||||
bottom_server = OthersItem(data=item, basic=basic, minio_client=minio_client)
|
||||
item_data = bottom_server.process()
|
||||
else:
|
||||
raise NotImplementedError(f"Item type {item['type']} not implemented")
|
||||
@@ -44,8 +44,8 @@ def process_layer(item, layers):
|
||||
body_layer = organize_body(item)
|
||||
layers.append(body_layer)
|
||||
return item['body_image'].size
|
||||
elif item['name'] == 'accessories':
|
||||
front_layer, back_layer = organize_accessories(item)
|
||||
elif item['name'] == 'others':
|
||||
front_layer, back_layer = organize_others(item)
|
||||
layers.append(front_layer)
|
||||
layers.append(back_layer)
|
||||
else:
|
||||
|
||||
@@ -9,10 +9,10 @@ class BaseItem:
|
||||
self.result.update(basic)
|
||||
|
||||
|
||||
class AccessoriesItem(BaseItem):
|
||||
class OthersItem(BaseItem):
|
||||
def __init__(self, data, basic, minio_client):
|
||||
super().__init__(data, basic)
|
||||
self.Accessories_pipeline = [
|
||||
self.Others_pipeline = [
|
||||
LoadImage(minio_client),
|
||||
# KeyPoint(),
|
||||
# ContourDetection(),
|
||||
@@ -26,7 +26,7 @@ class AccessoriesItem(BaseItem):
|
||||
]
|
||||
|
||||
def process(self):
|
||||
for item in self.Accessories_pipeline:
|
||||
for item in self.Others_pipeline:
|
||||
self.result = item(self.result)
|
||||
return self.result
|
||||
|
||||
|
||||
@@ -105,8 +105,8 @@ class LoadImage:
|
||||
keypoint = 'head_point'
|
||||
elif name == 'earring':
|
||||
keypoint = 'ear_point'
|
||||
elif name == 'accessories':
|
||||
keypoint = "accessories"
|
||||
elif name == 'others':
|
||||
keypoint = "others"
|
||||
else:
|
||||
raise KeyError(f"{name} does not belong to item category list: blouse, outwear, dress, trousers, skirt, "
|
||||
f"bag, shoes, hairstyle, earring.")
|
||||
|
||||
@@ -46,7 +46,7 @@ class Scaling:
|
||||
result['scale'] = result['scale_bag']
|
||||
elif result['keypoint'] == 'ear_point':
|
||||
result['scale'] = result['scale_earrings']
|
||||
elif result['keypoint'] == 'accessories':
|
||||
elif result['keypoint'] == 'others':
|
||||
# 由于没有识别配饰keypoint的模型 所以统一将配饰的两个关键点设定为 (0,0) (0,img.width)
|
||||
# 模特的关键点设定为(0,0) (0,320/2) 距离比例简写为 160 / img.width
|
||||
distance_clo = result['img_shape'][1]
|
||||
|
||||
@@ -20,7 +20,7 @@ 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', 'others'):
|
||||
ori_front_mask = result['front_mask'].copy()
|
||||
ori_back_mask = result['back_mask'].copy()
|
||||
|
||||
|
||||
@@ -58,14 +58,14 @@ def organize_clothing(layer):
|
||||
return front_layer, back_layer
|
||||
|
||||
|
||||
def organize_accessories(layer):
|
||||
def organize_others(layer):
|
||||
# 起始坐标
|
||||
start_point = (0, 0)
|
||||
layer['clothes_keypoint'] = {
|
||||
'accessories_left': [0, 0]
|
||||
'others_left': [0, 0]
|
||||
}
|
||||
layer['body_point_test'] = {
|
||||
'accessories_left': [0, 0]
|
||||
'others_left': [0, 0]
|
||||
}
|
||||
|
||||
start_point = calculate_start_point(layer['keypoint'], layer['scale'], layer['clothes_keypoint'], layer['body_point_test'], layer["offset"], layer["resize_scale"])
|
||||
|
||||
@@ -79,11 +79,11 @@ def synthesis(data, size, basic_info):
|
||||
_, 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)
|
||||
accessories_outer_mask = np.array(binary_body_mask)
|
||||
others_outer_mask = np.array(binary_body_mask)
|
||||
|
||||
top = True
|
||||
bottom = True
|
||||
accessories = True
|
||||
others = True
|
||||
i = len(data)
|
||||
while i:
|
||||
i -= 1
|
||||
@@ -111,7 +111,7 @@ def synthesis(data, size, basic_info):
|
||||
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 accessories and data[i]['name'] in ['accessories_front']:
|
||||
elif others and data[i]['name'] in ['others_front']:
|
||||
mask_shape = data[i]['mask'].shape
|
||||
y_offset, x_offset = data[i]['adaptive_position']
|
||||
# 初始化叠加区域的起始和结束位置
|
||||
@@ -121,13 +121,13 @@ def synthesis(data, size, basic_info):
|
||||
_, 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]
|
||||
accessories_outer_mask = background + accessories_outer_mask
|
||||
others_outer_mask = background + others_outer_mask
|
||||
pass
|
||||
elif bottom is False and top is False:
|
||||
break
|
||||
|
||||
all_mask = cv2.bitwise_or(top_outer_mask, bottom_outer_mask)
|
||||
all_mask = cv2.bitwise_or(all_mask, accessories_outer_mask)
|
||||
all_mask = cv2.bitwise_or(all_mask, others_outer_mask)
|
||||
|
||||
for layer in data:
|
||||
if layer['image'] is not None:
|
||||
|
||||
Reference in New Issue
Block a user