plutosss commited on
Commit
a1fbd3e
·
verified ·
1 Parent(s): 99fac33

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -4
app.py CHANGED
@@ -16,6 +16,7 @@ from torchvision.transforms import Compose
16
  from tqdm import tqdm
17
  import TEED.main as teed
18
  from TEED.main import parse_args
 
19
 
20
  from depthAnything.depth_anything.dpt import DepthAnything
21
  from depthAnything.depth_anything.util.transform import Resize, NormalizeImage, PrepareForNet
@@ -342,14 +343,17 @@ def process_images(input_folder='./output/merged_imgs'):
342
  except Exception as e:
343
  print(f"Error processing file {image_file}: {e}")
344
 
345
- def process_line(img_path='./input', outdir='./output'):
 
 
346
  depth_anything(img_path, os.path.join(outdir, "depth_anything"))
347
  teed_imgs(img_path, os.path.join(outdir, "teed_imgs"), [1, 7, 2])
348
  teed_imgs(os.path.join(outdir, "depth_anything"), os.path.join(outdir, "dp_teed_imgs"), [0, 7, 2])
349
  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])
350
- process_images(os.path.join(outdir, "merged_imgs")) # 处理merged_imgs文件夹中的图片
351
-
352
-
 
353
 
354
 
355
  if __name__ == '__main__':
@@ -365,3 +369,15 @@ if __name__ == '__main__':
365
  img_path = "input"
366
  outdir = "output"
367
  process_line(img_path,outdir)
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  from tqdm import tqdm
17
  import TEED.main as teed
18
  from TEED.main import parse_args
19
+ import gradio as gr
20
 
21
  from depthAnything.depth_anything.dpt import DepthAnything
22
  from depthAnything.depth_anything.util.transform import Resize, NormalizeImage, PrepareForNet
 
343
  except Exception as e:
344
  print(f"Error processing file {image_file}: {e}")
345
 
346
+ def process_line(img, outdir='./output'):
347
+ img_path = "./input"
348
+ cv2.imwrite(os.path.join(img_path, "input_image.png"), img) # 保存上传的图像
349
  depth_anything(img_path, os.path.join(outdir, "depth_anything"))
350
  teed_imgs(img_path, os.path.join(outdir, "teed_imgs"), [1, 7, 2])
351
  teed_imgs(os.path.join(outdir, "depth_anything"), os.path.join(outdir, "dp_teed_imgs"), [0, 7, 2])
352
  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])
353
+
354
+ # 返回处理后的最后一张图像
355
+ result_img_path = os.path.join(outdir, "merged_imgs", "your_final_image_name.png") # 修改为你的输出图像路径
356
+ return Image.open(result_img_path)
357
 
358
 
359
  if __name__ == '__main__':
 
369
  img_path = "input"
370
  outdir = "output"
371
  process_line(img_path,outdir)
372
+
373
+
374
+ if __name__ == '__main__':
375
+ # 创建 Gradio 接口
376
+ interface = gr.Interface(fn=process_line,
377
+ inputs=gr.Image(type="numpy", label="Upload Image"),
378
+ outputs=gr.Image(label="Output Image"),
379
+ title="Image Processing",
380
+ description="Upload an image to process it using depth-anything and TEED.")
381
+
382
+ # 启动 Gradio 接口
383
+ interface.launch()