1.1.2
Browse files
app.py
CHANGED
|
@@ -53,10 +53,10 @@ class DepthEstimator:
|
|
| 53 |
def estimate_depth(self, image_path):
|
| 54 |
try:
|
| 55 |
# Load image
|
| 56 |
-
|
| 57 |
|
| 58 |
# Resize image for processing
|
| 59 |
-
resized_image, new_size = self.resize_image(
|
| 60 |
|
| 61 |
rgb_image = load_rgb(resized_image.name)
|
| 62 |
f_px = rgb_image[-1]
|
|
@@ -231,14 +231,17 @@ async def estimate_depth_endpoint(file: UploadFile = File(...), mask: UploadFile
|
|
| 231 |
content={"error": "Depth estimation failed"}
|
| 232 |
)
|
| 233 |
|
| 234 |
-
# Resize image to match depth map size
|
| 235 |
resized_image = cv2.resize(image, new_size)
|
|
|
|
|
|
|
|
|
|
| 236 |
|
| 237 |
-
# Find key pixels
|
| 238 |
-
topmost_pixel = find_topmost_pixel(
|
| 239 |
|
| 240 |
# Calculate distance
|
| 241 |
-
distance_meters = estimate_real_world_distance(depth_map, topmost_pixel,
|
| 242 |
|
| 243 |
# Clean up
|
| 244 |
os.unlink(temp_file_path)
|
|
@@ -265,6 +268,11 @@ async def estimate_depth_endpoint(file: UploadFile = File(...), mask: UploadFile
|
|
| 265 |
os.unlink(temp_file_path)
|
| 266 |
except:
|
| 267 |
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
return JSONResponse(
|
| 269 |
status_code=500,
|
| 270 |
content={"error": str(e)}
|
|
|
|
| 53 |
def estimate_depth(self, image_path):
|
| 54 |
try:
|
| 55 |
# Load image
|
| 56 |
+
|
| 57 |
|
| 58 |
# Resize image for processing
|
| 59 |
+
resized_image, new_size = self.resize_image(image_path)
|
| 60 |
|
| 61 |
rgb_image = load_rgb(resized_image.name)
|
| 62 |
f_px = rgb_image[-1]
|
|
|
|
| 231 |
content={"error": "Depth estimation failed"}
|
| 232 |
)
|
| 233 |
|
| 234 |
+
# Resize image and mask to match depth map size
|
| 235 |
resized_image = cv2.resize(image, new_size)
|
| 236 |
+
resized_mask = cv2.resize(mask, new_size)
|
| 237 |
+
|
| 238 |
+
|
| 239 |
|
| 240 |
+
# Find key pixels from the mask
|
| 241 |
+
topmost_pixel = find_topmost_pixel(resized_mask)
|
| 242 |
|
| 243 |
# Calculate distance
|
| 244 |
+
distance_meters = estimate_real_world_distance(depth_map, topmost_pixel, resized_mask)
|
| 245 |
|
| 246 |
# Clean up
|
| 247 |
os.unlink(temp_file_path)
|
|
|
|
| 268 |
os.unlink(temp_file_path)
|
| 269 |
except:
|
| 270 |
pass
|
| 271 |
+
if 'temp_file_path_mask' in locals():
|
| 272 |
+
try:
|
| 273 |
+
os.unlink(temp_file_path_mask)
|
| 274 |
+
except:
|
| 275 |
+
pass
|
| 276 |
return JSONResponse(
|
| 277 |
status_code=500,
|
| 278 |
content={"error": str(e)}
|