Spaces:
Running
on
Zero
Running
on
Zero
图片调整回原始尺寸
Browse files
app.py
CHANGED
@@ -147,6 +147,7 @@ def start_tryon(dict, garm_img, garment_des, is_checked, is_checked_crop, denois
|
|
147 |
# 2. 图像预处理 - 调整服装和人物图像大小
|
148 |
garm_img = garm_img.convert("RGB").resize((768,1024))
|
149 |
human_img_orig = dict["background"].convert("RGB")
|
|
|
150 |
|
151 |
# 2.1 如果启用裁剪,按3:4比例裁剪人物图像
|
152 |
if is_checked_crop:
|
@@ -260,12 +261,11 @@ def start_tryon(dict, garm_img, garment_des, is_checked, is_checked_crop, denois
|
|
260 |
|
261 |
# 7. 后处理 - 处理裁剪情况并返回结果
|
262 |
if is_checked_crop:
|
263 |
-
|
264 |
-
|
265 |
-
return human_img_orig, mask_gray
|
266 |
else:
|
267 |
-
|
268 |
-
|
269 |
|
270 |
garm_list = os.listdir(os.path.join(example_path,"cloth"))
|
271 |
garm_list_path = [os.path.join(example_path,"cloth",garm) for garm in garm_list]
|
@@ -344,11 +344,9 @@ with image_blocks as demo:
|
|
344 |
gr.Markdown("###### [Change Clothes AI](https://changeclothesai.online/)")
|
345 |
gr.Markdown("###### [Describe Image AI](https://describeimageai.online/)")
|
346 |
|
347 |
-
|
348 |
try_button.click(fn=start_tryon, inputs=[imgs, garm_img, prompt, is_checked,is_checked_crop, denoise_steps, seed, category], outputs=[image_out,masked_img], api_name='tryon')
|
349 |
|
350 |
|
351 |
|
352 |
|
353 |
image_blocks.launch()
|
354 |
-
|
|
|
147 |
# 2. 图像预处理 - 调整服装和人物图像大小
|
148 |
garm_img = garm_img.convert("RGB").resize((768,1024))
|
149 |
human_img_orig = dict["background"].convert("RGB")
|
150 |
+
orig_size = human_img_orig.size # 保存原始尺寸
|
151 |
|
152 |
# 2.1 如果启用裁剪,按3:4比例裁剪人物图像
|
153 |
if is_checked_crop:
|
|
|
261 |
|
262 |
# 7. 后处理 - 处理裁剪情况并返回结果
|
263 |
if is_checked_crop:
|
264 |
+
# 将生成的图片和mask调整到裁剪后的尺寸
|
265 |
+
return images[0].resize(crop_size), mask_gray.resize(crop_size)
|
|
|
266 |
else:
|
267 |
+
# 直接将生成的图片和mask调整到原始尺寸
|
268 |
+
return images[0].resize(orig_size), mask_gray.resize(orig_size)
|
269 |
|
270 |
garm_list = os.listdir(os.path.join(example_path,"cloth"))
|
271 |
garm_list_path = [os.path.join(example_path,"cloth",garm) for garm in garm_list]
|
|
|
344 |
gr.Markdown("###### [Change Clothes AI](https://changeclothesai.online/)")
|
345 |
gr.Markdown("###### [Describe Image AI](https://describeimageai.online/)")
|
346 |
|
|
|
347 |
try_button.click(fn=start_tryon, inputs=[imgs, garm_img, prompt, is_checked,is_checked_crop, denoise_steps, seed, category], outputs=[image_out,masked_img], api_name='tryon')
|
348 |
|
349 |
|
350 |
|
351 |
|
352 |
image_blocks.launch()
|
|