adpro commited on
Commit
d95f5f3
·
verified ·
1 Parent(s): f6e7520

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -4,15 +4,22 @@ import numpy as np
4
  from PIL import Image
5
  import uvicorn
6
  import cv2
7
-
 
 
8
  app = FastAPI()
9
 
 
 
 
10
  @app.post("/analyze_path/")
11
  async def analyze_path(file: UploadFile = File(...)):
12
  image_bytes = await file.read()
13
  image = Image.open(io.BytesIO(image_bytes)).convert("L") # Chuyển ảnh sang grayscale
14
- depth_map = np.array(image)
15
- flipped_depth_map = cv2.flip(depth_map, -1)
 
 
16
  # Phân tích ảnh Depth Map
17
  command = detect_path(flipped_depth_map)
18
 
 
4
  from PIL import Image
5
  import uvicorn
6
  import cv2
7
+ from fastdepth import FastDepth
8
+ model = FastDepth(pretrained=True)
9
+ model.eval()
10
  app = FastAPI()
11
 
12
+ def analyzepath(image):
13
+ depth_map = model(image).squeeze().cpu().numpy()
14
+ return detect_path(depth_map) # Xử lý đường đi nhanh hơn
15
  @app.post("/analyze_path/")
16
  async def analyze_path(file: UploadFile = File(...)):
17
  image_bytes = await file.read()
18
  image = Image.open(io.BytesIO(image_bytes)).convert("L") # Chuyển ảnh sang grayscale
19
+ mImage = cv2.flip(image, -1)
20
+ #depth_map = np.array(image)
21
+ depth_map = analyzepath(mImage)
22
+
23
  # Phân tích ảnh Depth Map
24
  command = detect_path(flipped_depth_map)
25