plutosss commited on
Commit
51f183c
·
verified ·
1 Parent(s): 69e47af

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -8
app.py CHANGED
@@ -349,15 +349,29 @@ def process_images(input_folder='./output/merged_imgs'):
349
 
350
  def process_line(img, outdir='./output'):
351
  img_path = "./input"
352
- cv2.imwrite(os.path.join(img_path, "input_image.png"), img) # 保存上传的图像
353
- depth_anything(img_path, os.path.join(outdir, "depth_anything"))
354
- teed_imgs(img_path, os.path.join(outdir, "teed_imgs"), [1, 7, 2])
355
- teed_imgs(os.path.join(outdir, "depth_anything"), os.path.join(outdir, "dp_teed_imgs"), [0, 7, 2])
356
- merge_images_in_2_folder(os.path.join(outdir, "teed_imgs"), os.path.join(outdir, "dp_teed_imgs"), os.path.join(outdir, "merged_imgs"), '_depth', 1, 'multiply', [[2, 0], [2, 1]], [1, 0])
357
 
358
- # 返回处理后的最后一张图像
359
- result_img_path = os.path.join(outdir, "merged_imgs", "your_final_image_name.png") # 修改为你的输出图像路径
360
- return Image.open(result_img_path)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
361
 
362
 
363
  if __name__ == '__main__':
 
349
 
350
  def process_line(img, outdir='./output'):
351
  img_path = "./input"
 
 
 
 
 
352
 
353
+ # 保存上传的图像
354
+ cv2.imwrite(os.path.join(img_path, "input_image.png"), img)
355
+
356
+ # 确保输出目录存在
357
+ os.makedirs(outdir, exist_ok=True)
358
+
359
+ try:
360
+ depth_anything(img_path, os.path.join(outdir, "depth_anything"))
361
+ teed_imgs(img_path, os.path.join(outdir, "teed_imgs"), [1, 7, 2])
362
+ teed_imgs(os.path.join(outdir, "depth_anything"), os.path.join(outdir, "dp_teed_imgs"), [0, 7, 2])
363
+ merge_images_in_2_folder(os.path.join(outdir, "teed_imgs"),
364
+ os.path.join(outdir, "dp_teed_imgs"),
365
+ os.path.join(outdir, "merged_imgs"),
366
+ '_depth', 1, 'multiply', [[2, 0], [2, 1]], [1, 0])
367
+
368
+ # 返回处理后的最后一张图像
369
+ result_img_path = os.path.join(outdir, "merged_imgs", "your_final_image_name.png") # 修改为你的输出图像路径
370
+ return Image.open(result_img_path)
371
+
372
+ except Exception as e:
373
+ print(f"Error processing the image: {e}")
374
+ return None
375
 
376
 
377
  if __name__ == '__main__':