Update app.py
Browse files
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 |
-
|
15 |
-
|
|
|
|
|
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 |
|