feat(新功能):
fix(修复bug): batch relight 图片size 填充 docs(文档变更): refactor(重构): test(增加测试):
This commit is contained in:
@@ -48,7 +48,7 @@ def batch_generate_relight(batch_request_data):
|
||||
prompt = data['prompt']
|
||||
product_type = data['product_type']
|
||||
image_url = data['image_url']
|
||||
image = oss_get_image(bucket=image_url.split('/')[0], object_name=image_url.split('/', 1)[1], data_type="cv2")
|
||||
image = pre_processing_image(image_url)
|
||||
tasks_id = data['tasks_id']
|
||||
|
||||
prompts = [prompt] * 1
|
||||
@@ -149,6 +149,48 @@ def batch_generate_relight(batch_request_data):
|
||||
logger.info(f" [x]Queue : {BATCH_GRI_RABBITMQ_QUEUES} | batch_tasks_id:{batch_tasks_id} | progress:OK | result_data_list:{result_data_list}")
|
||||
|
||||
|
||||
def pre_processing_image(image_url):
|
||||
image = oss_get_image(bucket=image_url.split('/')[0], object_name=image_url[image_url.find('/') + 1:], data_type="PIL")
|
||||
# 目标图片的尺寸
|
||||
target_width = 512
|
||||
target_height = 768
|
||||
|
||||
# 原始图片的尺寸
|
||||
original_width, original_height = image.size
|
||||
|
||||
# 计算宽度和高度的缩放比例
|
||||
width_ratio = target_width / original_width
|
||||
height_ratio = target_height / original_height
|
||||
|
||||
# 选择较小的缩放比例,确保图片能完整放入目标图片中
|
||||
scale_ratio = min(width_ratio, height_ratio)
|
||||
|
||||
# 计算调整后的尺寸
|
||||
new_width = int(original_width * scale_ratio)
|
||||
new_height = int(original_height * scale_ratio)
|
||||
|
||||
# 调整图片大小
|
||||
resized_image = image.resize((new_width, new_height))
|
||||
|
||||
# 创建一个 512x768 的透明图片
|
||||
result_image = Image.new("RGBA", (target_width, target_height), (255, 255, 255, 0))
|
||||
|
||||
# 计算需要粘贴的位置,使图片居中
|
||||
x_offset = (target_width - new_width) // 2
|
||||
y_offset = (target_height - new_height) // 2
|
||||
|
||||
# 将调整大小后的图片粘贴到透明图片上
|
||||
if resized_image.mode == "RGBA":
|
||||
result_image.paste(resized_image, (x_offset, y_offset), mask=resized_image.split()[3])
|
||||
else:
|
||||
result_image.paste(resized_image, (x_offset, y_offset))
|
||||
|
||||
image = np.array(result_image)
|
||||
|
||||
# image = cv2.cvtColor(image, cv2.COLOR_BGRA2RGBA)
|
||||
return image
|
||||
|
||||
|
||||
def publish_status(task_id, progress, result):
|
||||
connection = pika.BlockingConnection(pika.ConnectionParameters(**RABBITMQ_PARAMS))
|
||||
channel = connection.channel()
|
||||
@@ -171,14 +213,14 @@ if __name__ == '__main__':
|
||||
RelightItemModel(
|
||||
tasks_id="123-5464",
|
||||
product_type="overall",
|
||||
image_url="aida-users/89/product_image/02894523-19b5-46eb-a9c6-2f512f5fec84-0-89.png",
|
||||
image_url="test/703190759.png",
|
||||
prompt="Colorful black",
|
||||
direction="Right Light",
|
||||
),
|
||||
RelightItemModel(
|
||||
tasks_id="123-5464123",
|
||||
product_type="overall",
|
||||
image_url="aida-users/89/product_image/02894523-19b5-46eb-a9c6-2f512f5fec84-0-89.png",
|
||||
image_url="test/703190759.png",
|
||||
direction="Right Light",
|
||||
prompt="Colorful black",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user