@@ -2,12 +2,9 @@ import json
|
||||
|
||||
import pika
|
||||
|
||||
from app.core.config import RABBITMQ_PARAMS
|
||||
|
||||
|
||||
def publish_status(task_id, progress, result):
|
||||
connection = pika.BlockingConnection(pika.ConnectionParameters(**RABBITMQ_PARAMS))
|
||||
# connection = pika.BlockingConnection(pika.ConnectionParameters('10.1.2.190'))
|
||||
connection = pika.BlockingConnection(pika.ConnectionParameters('10.1.2.213'))
|
||||
channel = connection.channel()
|
||||
channel.queue_declare(queue='DesignBatch', durable=True)
|
||||
message = {'task_id': task_id, 'progress': progress, "result": result}
|
||||
@@ -18,7 +15,3 @@ def publish_status(task_id, progress, result):
|
||||
delivery_mode=2,
|
||||
))
|
||||
connection.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
publish_status("1", "1", "1")
|
||||
|
||||
@@ -85,7 +85,7 @@ def seg_preprocess(img_path):
|
||||
if ori_shape != (img_scale_w, img_scale_h):
|
||||
# mmcv.imresize(img, img_scale_h, img_scale_w) # 老代码 引以为戒!哈哈哈~ h和w写反了
|
||||
img = cv2.resize(img, (img_scale_h, img_scale_w))
|
||||
# img = mmcv.imnormalize(img, mean=np.array([123.675, 116.28, 103.53]), std=np.array([58.395, 57.12, 57.375]), to_rgb=True)
|
||||
img = mmcv.imnormalize(img, mean=np.array([123.675, 116.28, 103.53]), std=np.array([58.395, 57.12, 57.375]), to_rgb=True)
|
||||
preprocessed_img = np.expand_dims(img.transpose(2, 0, 1), axis=0)
|
||||
return preprocessed_img, ori_shape
|
||||
|
||||
|
||||
@@ -33,8 +33,8 @@ def organize_clothing(layer):
|
||||
mask=cv2.resize(layer['mask'], layer["front_image"].size),
|
||||
gradient_string=layer['gradient_string'] if 'gradient_string' in layer.keys() else "",
|
||||
pattern_image_url=layer['pattern_image_url'],
|
||||
pattern_image=layer['pattern_image'],
|
||||
# back_perspective_url=layer['back_perspective_url'] if 'back_perspective_url' in layer.keys() else ""
|
||||
pattern_image=layer['pattern_image']
|
||||
|
||||
)
|
||||
# 后片数据
|
||||
back_layer = dict(priority=-layer.get("priority", 0) if layer.get("layer_order", False) else PRIORITY_DICT.get(f'{layer["name"].lower()}_back', None),
|
||||
@@ -50,46 +50,6 @@ def organize_clothing(layer):
|
||||
mask=cv2.resize(layer['mask'], layer["front_image"].size),
|
||||
gradient_string=layer['gradient_string'] if 'gradient_string' in layer.keys() else "",
|
||||
pattern_image_url=layer['pattern_image_url'],
|
||||
# back_perspective_url=layer['back_perspective_url'] if 'back_perspective_url' in layer.keys() else ""
|
||||
)
|
||||
return front_layer, back_layer
|
||||
|
||||
|
||||
def organize_accessories(layer):
|
||||
# 起始坐标
|
||||
start_point = (0, 0)
|
||||
# 前片数据
|
||||
front_layer = dict(priority=layer['priority'] if layer.get("layer_order", False) else PRIORITY_DICT.get(f'{layer["name"].lower()}_front', None),
|
||||
name=f'{layer["name"].lower()}_front',
|
||||
image=layer["front_image"],
|
||||
# mask_image=layer['front_mask_image'],
|
||||
image_url=layer['front_image_url'],
|
||||
mask_url=layer['mask_url'],
|
||||
sacle=layer['scale'],
|
||||
clothes_keypoint=(0, 0),
|
||||
position=start_point,
|
||||
resize_scale=layer["resize_scale"],
|
||||
mask=cv2.resize(layer['mask'], layer["front_image"].size),
|
||||
gradient_string=layer['gradient_string'] if 'gradient_string' in layer.keys() else "",
|
||||
pattern_image_url=layer['pattern_image_url'],
|
||||
pattern_image=layer['pattern_image'],
|
||||
# back_perspective_url=layer['back_perspective_url'] if 'back_perspective_url' in layer.keys() else ""
|
||||
)
|
||||
# 后片数据
|
||||
back_layer = dict(priority=-layer.get("priority", 0) if layer.get("layer_order", False) else PRIORITY_DICT.get(f'{layer["name"].lower()}_back', None),
|
||||
name=f'{layer["name"].lower()}_back',
|
||||
image=layer["back_image"],
|
||||
# mask_image=layer['back_mask_image'],
|
||||
image_url=layer['back_image_url'],
|
||||
mask_url=layer['mask_url'],
|
||||
sacle=layer['scale'],
|
||||
clothes_keypoint=(0, 0),
|
||||
position=start_point,
|
||||
resize_scale=layer["resize_scale"],
|
||||
mask=cv2.resize(layer['mask'], layer["front_image"].size),
|
||||
gradient_string=layer['gradient_string'] if 'gradient_string' in layer.keys() else "",
|
||||
pattern_image_url=layer['pattern_image_url'],
|
||||
# back_perspective_url=layer['back_perspective_url'] if 'back_perspective_url' in layer.keys() else ""
|
||||
)
|
||||
return front_layer, back_layer
|
||||
|
||||
|
||||
@@ -79,11 +79,9 @@ 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)
|
||||
|
||||
top = True
|
||||
bottom = True
|
||||
accessories = True
|
||||
i = len(data)
|
||||
while i:
|
||||
i -= 1
|
||||
@@ -100,7 +98,7 @@ def synthesis(data, size, basic_info):
|
||||
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", "dress_front"]:
|
||||
# bottom = False
|
||||
bottom = False
|
||||
mask_shape = data[i]['mask'].shape
|
||||
y_offset, x_offset = data[i]['adaptive_position']
|
||||
# 初始化叠加区域的起始和结束位置
|
||||
@@ -111,23 +109,10 @@ 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']:
|
||||
mask_shape = data[i]['mask'].shape
|
||||
y_offset, x_offset = data[i]['adaptive_position']
|
||||
# 初始化叠加区域的起始和结束位置
|
||||
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)
|
||||
# 将叠加区域赋值为相应的像素值
|
||||
_, 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
|
||||
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)
|
||||
|
||||
for layer in data:
|
||||
if layer['image'] is not None:
|
||||
@@ -200,14 +185,12 @@ def update_base_size_priority(layers, size):
|
||||
# 计算透明背景图片的宽度
|
||||
min_x = min(info['position'][1] for info in layers)
|
||||
x_list = []
|
||||
new_height = 700
|
||||
for info in layers:
|
||||
if info['image'] is not None:
|
||||
x_list.append(info['position'][1] + info['image'].width)
|
||||
if info['name'] == 'mannequin':
|
||||
new_height = info['image'].height
|
||||
max_x = max(x_list)
|
||||
new_width = max_x - min_x
|
||||
new_height = 700
|
||||
# 更新坐标
|
||||
for info in layers:
|
||||
info['adaptive_position'] = (info['position'][0], info['position'][1] - min_x)
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
from PIL import Image
|
||||
|
||||
|
||||
def sketch_to_transparent(image, mask, transparency):
|
||||
# 打开原始图片
|
||||
image = image.convert("RGBA")
|
||||
# 打开mask图片,假设mask图片是灰度图,白色区域为要处理的区域,黑色区域为保留的区域
|
||||
mask = Image.fromarray(mask)
|
||||
|
||||
# 根据透明度调整因子,将透明度转换为0-255之间的值
|
||||
alpha_value = int((1 - transparency) * 255.0)
|
||||
|
||||
# 获取图片的像素数据
|
||||
image_pixels = image.load()
|
||||
mask_pixels = mask.load()
|
||||
|
||||
width, height = image.size
|
||||
|
||||
for y in range(height):
|
||||
for x in range(width):
|
||||
# 如果mask区域对应的像素为白色(值大于128,这里假设白色为要处理的区域,可根据实际情况调整)
|
||||
if mask_pixels[x, y] > 128:
|
||||
r, g, b, a = image_pixels[x, y]
|
||||
image_pixels[x, y] = (r, g, b, alpha_value)
|
||||
|
||||
return image
|
||||
Reference in New Issue
Block a user