Update app.py
Browse files
app.py
CHANGED
@@ -15,10 +15,11 @@ midas_transform = torch.hub.load("intel-isl/MiDaS", "transforms").default_transf
|
|
15 |
def estimate_depth(image):
|
16 |
"""Estimate depth map using MiDaS v3."""
|
17 |
image = image.convert("RGB")
|
|
|
18 |
input_tensor = midas_transform(image).unsqueeze(0).to(device)
|
19 |
with torch.no_grad():
|
20 |
depth = midas_model(input_tensor).squeeze().cpu().numpy()
|
21 |
-
depth = cv2.resize(depth, (image.
|
22 |
depth = (depth - depth.min()) / (depth.max() - depth.min()) * 255
|
23 |
return depth.astype(np.uint8)
|
24 |
|
|
|
15 |
def estimate_depth(image):
|
16 |
"""Estimate depth map using MiDaS v3."""
|
17 |
image = image.convert("RGB")
|
18 |
+
image = np.array(image) / 255.0 # Normalize and convert to NumPy array
|
19 |
input_tensor = midas_transform(image).unsqueeze(0).to(device)
|
20 |
with torch.no_grad():
|
21 |
depth = midas_model(input_tensor).squeeze().cpu().numpy()
|
22 |
+
depth = cv2.resize(depth, (image.shape[1], image.shape[0]))
|
23 |
depth = (depth - depth.min()) / (depth.max() - depth.min()) * 255
|
24 |
return depth.astype(np.uint8)
|
25 |
|