Merge branch 'develop'

# Conflicts:
#	app/service/design_fast/pipeline/split.py
This commit is contained in:
zhh
2025-09-22 17:56:18 +08:00
10 changed files with 70 additions and 27 deletions

View File

@@ -4,7 +4,8 @@ import logging
from fastapi import APIRouter from fastapi import APIRouter
from fastapi import HTTPException from fastapi import HTTPException
from app.core.config import SR_RABBITMQ_QUEUES, GI_RABBITMQ_QUEUES, GPI_RABBITMQ_QUEUES, GRI_RABBITMQ_QUEUES, OSS, JAVA_STREAM_API_URL, GMV_RABBITMQ_QUEUES, SLOGAN_RABBITMQ_QUEUES, GEN_SINGLE_LOGO_RABBITMQ_QUEUES, PS_RABBITMQ_QUEUES, BATCH_GPI_RABBITMQ_QUEUES, BATCH_GRI_RABBITMQ_QUEUES, BATCH_PS_RABBITMQ_QUEUES from app.core.config import SR_RABBITMQ_QUEUES, GI_RABBITMQ_QUEUES, GPI_RABBITMQ_QUEUES, GRI_RABBITMQ_QUEUES, OSS, JAVA_STREAM_API_URL, GMV_RABBITMQ_QUEUES, SLOGAN_RABBITMQ_QUEUES, GEN_SINGLE_LOGO_RABBITMQ_QUEUES, PS_RABBITMQ_QUEUES, BATCH_GPI_RABBITMQ_QUEUES, BATCH_GRI_RABBITMQ_QUEUES, \
BATCH_PS_RABBITMQ_QUEUES, RABBITMQ_ENV
from app.schemas.response_template import ResponseModel from app.schemas.response_template import ResponseModel
logger = logging.getLogger() logger = logging.getLogger()
@@ -14,6 +15,7 @@ router = APIRouter()
@router.get("{id}") @router.get("{id}")
def test(id: int): def test(id: int):
data = { data = {
"RABBITMQ_ENV":RABBITMQ_ENV,
"超分 SR_RABBITMQ_QUEUES": SR_RABBITMQ_QUEUES, "超分 SR_RABBITMQ_QUEUES": SR_RABBITMQ_QUEUES,
"多视角 GMV_RABBITMQ_QUEUES": GMV_RABBITMQ_QUEUES, "多视角 GMV_RABBITMQ_QUEUES": GMV_RABBITMQ_QUEUES,
"pose transform PS_RABBITMQ_QUEUES": PS_RABBITMQ_QUEUES, "pose transform PS_RABBITMQ_QUEUES": PS_RABBITMQ_QUEUES,

View File

@@ -9,11 +9,11 @@ load_dotenv(os.path.join(BASE_DIR, '.env'))
class Settings(BaseSettings): class Settings(BaseSettings):
PROJECT_NAME: str = os.getenv('PROJECT_NAME', 'FASTAPI BASE') PROJECT_NAME: str = 'FASTAPI BASE'
SECRET_KEY: str = os.getenv('SECRET_KEY', '') SECRET_KEY: str = ''
API_PREFIX: str = '' API_PREFIX: str = ''
BACKEND_CORS_ORIGINS: list[str] = ['*'] BACKEND_CORS_ORIGINS: list[str] = ['*']
DATABASE_URL: str = os.getenv('SQL_DATABASE_URL', '') DATABASE_URL: str = ''
ACCESS_TOKEN_EXPIRE_SECONDS: int = 60 * 60 * 24 * 7 # Token expired after 7 days ACCESS_TOKEN_EXPIRE_SECONDS: int = 60 * 60 * 24 * 7 # Token expired after 7 days
SECURITY_ALGORITHM: str = 'HS256' SECURITY_ALGORITHM: str = 'HS256'
LOGGING_CONFIG_FILE: str = os.path.join(BASE_DIR, 'logging_env.py') LOGGING_CONFIG_FILE: str = os.path.join(BASE_DIR, 'logging_env.py')
@@ -36,12 +36,14 @@ else:
RECOMMEND_PATH_PREFIX = "app/service/recommend/" RECOMMEND_PATH_PREFIX = "app/service/recommend/"
CHROMADB_PATH = "/chromadb/" CHROMADB_PATH = "/chromadb/"
# RABBITMQ_ENV = "" # 生产环境
RABBITMQ_ENV = "-prod" # 生产环境# RABBITMQ_ENV = os.getenv("RABBITMQ_ENV", "-dev")
# RABBITMQ_ENV = "-dev" # 开发环境
# RABBITMQ_ENV = "-local" # 本地测试环境 # RABBITMQ_ENV = "-local" # 本地测试环境
JAVA_STREAM_API_URL = os.getenv("JAVA_STREAM_API_URL", "https://api.aida.com.hk/api/third/party/receiveDesignResults") if RABBITMQ_ENV == "-dev":
JAVA_STREAM_API_URL = f"https://develop.api.aida.com.hk/api/third/party/receiveDesignResults"
elif RABBITMQ_ENV == "-prod":
JAVA_STREAM_API_URL = f"https://api.aida.com.hk/api/third/party/receiveDesignResults"
settings = Settings() settings = Settings()
@@ -106,7 +108,7 @@ OPENAI_MODEL_LIST = {"gpt-3.5-turbo-0613",
SR_MODEL_NAME = "super_resolution" SR_MODEL_NAME = "super_resolution"
SR_TRITON_URL = "10.1.1.240:10031" SR_TRITON_URL = "10.1.1.240:10031"
SR_MINIO_BUCKET = "aida-users" SR_MINIO_BUCKET = "aida-users"
SR_RABBITMQ_QUEUES = os.getenv("SR_RABBITMQ_QUEUES", f"SuperResolution{RABBITMQ_ENV}") SR_RABBITMQ_QUEUES = f"SuperResolution{RABBITMQ_ENV}"
# GenerateImage service config # GenerateImage service config
FAST_GI_MODEL_URL = '10.1.1.243:10011' FAST_GI_MODEL_URL = '10.1.1.243:10011'

View File

@@ -201,9 +201,10 @@ def design_generate_v2(request_data):
# 发送结果给java端 # 发送结果给java端
url = JAVA_STREAM_API_URL url = JAVA_STREAM_API_URL
# xu_pei_test_url = "https://cd21b9110505.ngrok-free.app/api/third/party/receiveDesignResults" # xu_pei_test_url = "https://cd21b9110505.ngrok-free.app/api/third/party/receiveDesignResults"
tianxaing_test_url = "https://c2ae520723c9.ngrok-free.app/api/third/party/receiveDesignResults"
logger.info(f"java 回调 -> {url}") logger.info(f"java 回调 -> {url}")
# logger.info(f"xupei java 回调 -> {xu_pei_test_url}") # logger.info(f"xupei java 回调 -> {xu_pei_test_url}")
logger.info(f"tianxiang java 回调 -> {tianxaing_test_url}")
headers = { headers = {
'Accept': "*/*", 'Accept': "*/*",
@@ -218,10 +219,13 @@ def design_generate_v2(request_data):
# 打印结果 # 打印结果
logger.info(response.text) logger.info(response.text)
# response = post_request(xu_pei_test_url, json_data=items_response, headers=headers) # test_response = post_request(xu_pei_test_url, json_data=items_response, headers=headers)
# if response: test_response = post_request(tianxaing_test_url, json_data=items_response, headers=headers)
if test_response:
# 打印结果 # 打印结果
# logger.info(f"xupei test response : {response.text}") # logger.info(f"xupei test response : {test_response.text}")
logger.info(f"tianxiang test response : {test_response.text}")
for step, object in enumerate(objects_data): for step, object in enumerate(objects_data):
t = threading.Thread(target=process_object, args=(step, object)) t = threading.Thread(target=process_object, args=(step, object))

View File

@@ -15,8 +15,8 @@ class AccessoriesItem(BaseItem):
self.Accessories_pipeline = [ self.Accessories_pipeline = [
LoadImage(minio_client), LoadImage(minio_client),
# KeyPoint(), # KeyPoint(),
ContourDetection(), # ContourDetection(),
# Segmentation(minio_client), Segmentation(minio_client),
# BackPerspective(minio_client), # BackPerspective(minio_client),
Color(minio_client), Color(minio_client),
PrintPainting(minio_client), PrintPainting(minio_client),

View File

@@ -22,7 +22,7 @@ class Color:
resize_pattern = cv2.resize(pattern, (dim_image_w, dim_image_h), interpolation=cv2.INTER_AREA) resize_pattern = cv2.resize(pattern, (dim_image_w, dim_image_h), interpolation=cv2.INTER_AREA)
# 无色 # 无色
elif "color" not in result.keys() or result['color'] == "": elif "color" not in result.keys() or result['color'] == "":
result['final_image'] = result['pattern_image'] = result['single_image'] = result['image'] result['no_seg_sketch'] = result['final_image'] = result['pattern_image'] = result['single_image'] = result['image']
result['alpha'] = 100 / 255.0 result['alpha'] = 100 / 255.0
return result return result
# 正常颜色 # 正常颜色
@@ -59,6 +59,8 @@ class Color:
tmp2 = (result['final_image'] * (temp_fg / 255)).astype(np.uint8) tmp2 = (result['final_image'] * (temp_fg / 255)).astype(np.uint8)
result['single_image'] = cv2.add(tmp1, tmp2) result['single_image'] = cv2.add(tmp1, tmp2)
result['alpha'] = 100 / 255.0 result['alpha'] = 100 / 255.0
result['no_seg_sketch'] = result['final_image'].copy()
return result return result
def get_gradient(self, bucket_name, object_name): def get_gradient(self, bucket_name, object_name):

View File

@@ -24,6 +24,7 @@ class PrintPainting:
if result['resize_scale'][0] == 1.0 and result['resize_scale'][1] == 1.0: if result['resize_scale'][0] == 1.0 and result['resize_scale'][1] == 1.0:
pass pass
else: else:
# 2025-9-19 印花调整 印花坐标按照sketch的缩放比调整
height, width = result['pattern_image'].shape[:2] height, width = result['pattern_image'].shape[:2]
new_width = int(width * result['resize_scale'][0]) new_width = int(width * result['resize_scale'][0])
new_height = int(height * result['resize_scale'][1]) new_height = int(height * result['resize_scale'][1])
@@ -34,6 +35,7 @@ class PrintPainting:
result['gray'] = cv2.resize(result['gray'], (new_width, new_height)) result['gray'] = cv2.resize(result['gray'], (new_width, new_height))
if overall_print['print_path_list']: if overall_print['print_path_list']:
overall_print['location'][0] = [x * y for x, y in zip(overall_print['location'][0], result['resize_scale'])]
painting_dict = {'dim_image_h': result['pattern_image'].shape[0], 'dim_image_w': result['pattern_image'].shape[1]} painting_dict = {'dim_image_h': result['pattern_image'].shape[0], 'dim_image_w': result['pattern_image'].shape[1]}
result['print_image'] = result['pattern_image'] result['print_image'] = result['pattern_image']
if "print_angle_list" in overall_print.keys() and overall_print['print_angle_list'][0] != 0: if "print_angle_list" in overall_print.keys() and overall_print['print_angle_list'][0] != 0:
@@ -50,6 +52,9 @@ class PrintPainting:
result['single_image'] = result['final_image'] = result['pattern_image'] = result['print_image'] result['single_image'] = result['final_image'] = result['pattern_image'] = result['print_image']
if single_print['print_path_list']: if single_print['print_path_list']:
# 2025-9-19 印花调整 印花坐标按照sketch的缩放比调整
sketch_resize_scale = result['resize_scale']
print_background = np.zeros((result['pattern_image'].shape[0], result['pattern_image'].shape[1], 3), dtype=np.uint8) print_background = np.zeros((result['pattern_image'].shape[0], result['pattern_image'].shape[1], 3), dtype=np.uint8)
mask_background = np.zeros((result['pattern_image'].shape[0], result['pattern_image'].shape[1], 3), dtype=np.uint8) mask_background = np.zeros((result['pattern_image'].shape[0], result['pattern_image'].shape[1], 3), dtype=np.uint8)
for i in range(len(single_print['print_path_list'])): for i in range(len(single_print['print_path_list'])):
@@ -67,8 +72,8 @@ class PrintPainting:
rotated_resized_source_mask = resized_source_mask.rotate(-single_print['print_angle_list'][i]) rotated_resized_source_mask = resized_source_mask.rotate(-single_print['print_angle_list'][i])
source_image_pil = Image.fromarray(cv2.cvtColor(print_background, cv2.COLOR_BGR2RGB)) source_image_pil = Image.fromarray(cv2.cvtColor(print_background, cv2.COLOR_BGR2RGB))
source_image_pil_mask = Image.fromarray(cv2.cvtColor(mask_background, cv2.COLOR_BGR2RGB)) source_image_pil_mask = Image.fromarray(cv2.cvtColor(mask_background, cv2.COLOR_BGR2RGB))
source_image_pil.paste(rotated_resized_source, (int(single_print['location'][i][0]), int(single_print['location'][i][1])), rotated_resized_source) source_image_pil.paste(rotated_resized_source, (int(single_print['location'][i][0] * sketch_resize_scale[0]), int(single_print['location'][i][1] * sketch_resize_scale[1])), rotated_resized_source)
source_image_pil_mask.paste(rotated_resized_source_mask, (int(single_print['location'][i][0]), int(single_print['location'][i][1])), rotated_resized_source_mask) source_image_pil_mask.paste(rotated_resized_source_mask, (int(single_print['location'][i][0] * sketch_resize_scale[0]), int(single_print['location'][i][1] * sketch_resize_scale[1])), rotated_resized_source_mask)
print_background = cv2.cvtColor(np.array(source_image_pil), cv2.COLOR_RGBA2BGR) print_background = cv2.cvtColor(np.array(source_image_pil), cv2.COLOR_RGBA2BGR)
mask_background = cv2.cvtColor(np.array(source_image_pil_mask), cv2.COLOR_RGBA2BGR) mask_background = cv2.cvtColor(np.array(source_image_pil_mask), cv2.COLOR_RGBA2BGR)
ret, mask_background = cv2.threshold(mask_background, 124, 255, cv2.THRESH_BINARY) ret, mask_background = cv2.threshold(mask_background, 124, 255, cv2.THRESH_BINARY)
@@ -146,7 +151,9 @@ class PrintPainting:
img_bg = cv2.bitwise_and(result['pattern_image'], result['pattern_image'], mask=cv2.bitwise_not(print_mask)) img_bg = cv2.bitwise_and(result['pattern_image'], result['pattern_image'], mask=cv2.bitwise_not(print_mask))
mask_mo = np.expand_dims(print_mask, axis=2).repeat(3, axis=2) mask_mo = np.expand_dims(print_mask, axis=2).repeat(3, axis=2)
gray_mo = np.expand_dims(result['gray'], axis=2).repeat(3, axis=2) gray_mo = np.expand_dims(result['gray'], axis=2).repeat(3, axis=2)
img_fg = (img_fg * (mask_mo / 255) * (gray_mo / 255)).astype(np.uint8) img_fg = (img_fg * (mask_mo / 255) * (gray_mo / 255)).astype(np.uint8) # 当sketch 图像为灰色时(非纯白) 印花*灰度图像会导致印花在sketch上颜色变暗
# img_fg = (img_fg * (mask_mo / 255) ).astype(np.uint8) # 不过灰度图像
result['final_image'] = cv2.add(img_bg, img_fg) result['final_image'] = cv2.add(img_bg, img_fg)
canvas = np.full_like(result['final_image'], 255) canvas = np.full_like(result['final_image'], 255)
temp_bg = np.expand_dims(cv2.bitwise_not(result['mask']), axis=2).repeat(3, axis=2) temp_bg = np.expand_dims(cv2.bitwise_not(result['mask']), axis=2).repeat(3, axis=2)
@@ -156,6 +163,9 @@ class PrintPainting:
result['single_image'] = cv2.add(tmp1, tmp2) result['single_image'] = cv2.add(tmp1, tmp2)
if element_print['element_path_list']: if element_print['element_path_list']:
# 2025-9-19 印花调整 印花坐标按照sketch的缩放比调整
sketch_resize_scale = result['resize_scale']
print_background = np.zeros((result['final_image'].shape[0], result['final_image'].shape[1], 3), dtype=np.uint8) print_background = np.zeros((result['final_image'].shape[0], result['final_image'].shape[1], 3), dtype=np.uint8)
mask_background = np.zeros((result['final_image'].shape[0], result['final_image'].shape[1], 3), dtype=np.uint8) mask_background = np.zeros((result['final_image'].shape[0], result['final_image'].shape[1], 3), dtype=np.uint8)
for i in range(len(element_print['element_path_list'])): for i in range(len(element_print['element_path_list'])):
@@ -173,8 +183,8 @@ class PrintPainting:
source_image_pil = Image.fromarray(cv2.cvtColor(print_background, cv2.COLOR_BGR2RGB)) source_image_pil = Image.fromarray(cv2.cvtColor(print_background, cv2.COLOR_BGR2RGB))
source_image_pil_mask = Image.fromarray(cv2.cvtColor(mask_background, cv2.COLOR_BGR2RGB)) source_image_pil_mask = Image.fromarray(cv2.cvtColor(mask_background, cv2.COLOR_BGR2RGB))
source_image_pil.paste(rotated_resized_source, (int(element_print['location'][i][0]), int(element_print['location'][i][1])), rotated_resized_source) source_image_pil.paste(rotated_resized_source, (int(element_print['location'][i][0] * sketch_resize_scale[0]), int(element_print['location'][i][1] * sketch_resize_scale[1])), rotated_resized_source)
source_image_pil_mask.paste(rotated_resized_source_mask, (int(element_print['location'][i][0]), int(element_print['location'][i][1])), rotated_resized_source_mask) source_image_pil_mask.paste(rotated_resized_source_mask, (int(element_print['location'][i][0] * sketch_resize_scale[1]), int(element_print['location'][i][1] * sketch_resize_scale[1])), rotated_resized_source_mask)
print_background = cv2.cvtColor(np.array(source_image_pil), cv2.COLOR_RGBA2BGR) print_background = cv2.cvtColor(np.array(source_image_pil), cv2.COLOR_RGBA2BGR)
mask_background = cv2.cvtColor(np.array(source_image_pil_mask), cv2.COLOR_RGBA2BGR) mask_background = cv2.cvtColor(np.array(source_image_pil_mask), cv2.COLOR_RGBA2BGR)

View File

@@ -67,7 +67,6 @@ class Split(object):
# mask_image = np.zeros((height, width, 3)) # mask_image = np.zeros((height, width, 3))
# mask_image[front_mask != 0] = [0, 0, 255] # mask_image[front_mask != 0] = [0, 0, 255]
# 切换为原始图片尺寸------------------------------- # 切换为原始图片尺寸-------------------------------
height, width = ori_front_mask.shape height, width = ori_front_mask.shape
mask_image = np.zeros((height, width, 3)) mask_image = np.zeros((height, width, 3))
@@ -113,7 +112,6 @@ class Split(object):
# mask_image[back_mask != 0] = [0, 255, 0] # mask_image[back_mask != 0] = [0, 255, 0]
mask_image[ori_back_mask != 0] = [0, 255, 0] mask_image[ori_back_mask != 0] = [0, 255, 0]
rbga_mask = rgb_to_rgba(mask_image, ori_front_mask + ori_back_mask) rbga_mask = rgb_to_rgba(mask_image, ori_front_mask + ori_back_mask)
mask_pil = Image.fromarray(cvtColor(rbga_mask.astype(np.uint8), COLOR_BGR2RGBA)) mask_pil = Image.fromarray(cvtColor(rbga_mask.astype(np.uint8), COLOR_BGR2RGBA))
image_data = io.BytesIO() image_data = io.BytesIO()
@@ -124,7 +122,7 @@ class Split(object):
result['mask_url'] = req.bucket_name + "/" + req.object_name result['mask_url'] = req.bucket_name + "/" + req.object_name
# 创建中间图层 # 创建中间图层
result_pattern_image_rgba = rgb_to_rgba(result['pattern_image'], result['mask']) result_pattern_image_rgba = rgb_to_rgba(result['no_seg_sketch'], ori_front_mask + ori_back_mask)
result_pattern_image_pil = Image.fromarray(cvtColor(result_pattern_image_rgba, COLOR_BGR2RGBA)) result_pattern_image_pil = Image.fromarray(cvtColor(result_pattern_image_rgba, COLOR_BGR2RGBA))
result['pattern_image'], result['pattern_image_url'], _ = upload_png_mask(self.minio_client, result_pattern_image_pil, f'{generate_uuid()}') result['pattern_image'], result['pattern_image_url'], _ = upload_png_mask(self.minio_client, result_pattern_image_pil, f'{generate_uuid()}')
return result return result

View File

@@ -58,6 +58,15 @@ def organize_clothing(layer):
def organize_accessories(layer): def organize_accessories(layer):
# 起始坐标 # 起始坐标
start_point = (0, 0) start_point = (0, 0)
layer['clothes_keypoint'] = {
'accessories_left': [0, 0]
}
layer['body_point_test'] = {
'accessories_left': [0, 0]
}
start_point = calculate_start_point(layer['keypoint'], layer['scale'], layer['clothes_keypoint'], layer['body_point_test'], layer["offset"], layer["resize_scale"])
# 前片数据 # 前片数据
front_layer = dict(priority=layer['priority'] if layer.get("layer_order", False) else PRIORITY_DICT.get(f'{layer["name"].lower()}_front', None), 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', name=f'{layer["name"].lower()}_front',

View File

@@ -207,7 +207,7 @@ def update_base_size_priority(layers, size):
if info['name'] == 'mannequin': if info['name'] == 'mannequin':
new_height = info['image'].height new_height = info['image'].height
max_x = max(x_list) max_x = max(x_list)
new_width = max_x - min_x new_width = max_x - min_x * 2
# 更新坐标 # 更新坐标
for info in layers: for info in layers:
info['adaptive_position'] = (info['position'][0], info['position'][1] - min_x) info['adaptive_position'] = (info['position'][0], info['position'][1] - min_x)

View File

@@ -5,7 +5,7 @@ from io import BytesIO
import cv2 import cv2
import numpy as np import numpy as np
import urllib3 import urllib3
from PIL import Image from PIL import Image, ImageDraw
from minio import Minio from minio import Minio
from app.core.config import * from app.core.config import *
@@ -82,7 +82,7 @@ if __name__ == '__main__':
# url = "aida-users/89/sketchboard/female/Dress/e6724ab7-8d3f-4677-abe0-c3e42ab7af85.jpeg" # 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/87/print/956614a2-7e75-4fbe-9ed0-c1831e37a2c9-4-87.png"
# url = "aida-users/89/single_logo/123-89.png" # url = "aida-users/89/single_logo/123-89.png"
url = "aida-users/89/123-89.png" url = "aida-results/result_d2577888-92d7-11f0-9cfd-e0d362103998.png"
# url = "aida-collection-element/12148/Sketchboard/95ea577b-305b-4a62-b30a-39c0dd3ddb3f.png" # url = "aida-collection-element/12148/Sketchboard/95ea577b-305b-4a62-b30a-39c0dd3ddb3f.png"
read_type = "2" read_type = "2"
@@ -92,4 +92,20 @@ if __name__ == '__main__':
cv2.waitKey(0) cv2.waitKey(0)
else: else:
img = oss_get_image(oss_client=minio_client, bucket=url.split('/')[0], object_name=url[url.find('/') + 1:], data_type=read_type) img = oss_get_image(oss_client=minio_client, bucket=url.split('/')[0], object_name=url[url.find('/') + 1:], data_type=read_type)
draw = ImageDraw.Draw(img)
# 获取图片尺寸
width, height = img.size
img
# 计算中心点坐标
center_x = width // 2
center_y = height // 2
# 绘制垂直中心线(红色)
draw.line(
[(center_x, 0), (center_x, height)], # 从顶部到底部的垂直线
fill=(255, 0, 0), # 红色 (R, G, B)
width=2 # 线宽
)
img.show() img.show()
img.save("result.png")