Alessio Grancini
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -264,15 +264,24 @@ def get_detection_data(image_data):
|
|
| 264 |
cls_id, cls_name, center, mask, color_bgr, confidence = obj
|
| 265 |
x1, y1, x2, y2 = get_bbox_from_mask(mask)
|
| 266 |
|
| 267 |
-
depth_value = depth_at_center(depthmap, [x1, y1, x2, y2])
|
| 268 |
|
| 269 |
# Debug: Log original center and vertices (1536x1024)
|
| 270 |
print(f"Debug - Object {idx}: Original Center = {center}, Original Vertices = {get_box_vertices([x1, y1, x2, y2])}")
|
| 271 |
|
| 272 |
# Handle invalid or NaN depth values
|
| 273 |
-
if depth_value is None or np.isnan(depth_value) or not isinstance(depth_value, (int, float)) or depth_value <= 0:
|
| 274 |
-
print(f"Warning: Invalid depth value ({depth_value}) for Object {idx}. Using default depth of 1.0...")
|
| 275 |
-
depth_value = 1.0 # Default to 1.0 if depth is invalid or NaN
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
|
| 277 |
|
| 278 |
# Scale from 1536x1024 to 1512x1008, ensuring values fit within bounds
|
|
@@ -313,7 +322,8 @@ def get_detection_data(image_data):
|
|
| 313 |
"vertices": get_box_vertices([x1, y1, x2, y2])
|
| 314 |
},
|
| 315 |
"center_2d": center, # Add 2D center in screen space
|
| 316 |
-
"distance":
|
|
|
|
| 317 |
"color": color_rgb,
|
| 318 |
"confidence": float(confidence)
|
| 319 |
|
|
|
|
| 264 |
cls_id, cls_name, center, mask, color_bgr, confidence = obj
|
| 265 |
x1, y1, x2, y2 = get_bbox_from_mask(mask)
|
| 266 |
|
| 267 |
+
#depth_value = depth_at_center(depthmap, [x1, y1, x2, y2])
|
| 268 |
|
| 269 |
# Debug: Log original center and vertices (1536x1024)
|
| 270 |
print(f"Debug - Object {idx}: Original Center = {center}, Original Vertices = {get_box_vertices([x1, y1, x2, y2])}")
|
| 271 |
|
| 272 |
# Handle invalid or NaN depth values
|
| 273 |
+
#if depth_value is None or np.isnan(depth_value) or not isinstance(depth_value, (int, float)) or depth_value <= 0:
|
| 274 |
+
#print(f"Warning: Invalid depth value ({depth_value}) for Object {idx}. Using default depth of 1.0...")
|
| 275 |
+
#depth_value = 1.0 # Default to 1.0 if depth is invalid or NaN
|
| 276 |
+
|
| 277 |
+
# Use get_masked_depth to get mean depth directly from depthmap and mask
|
| 278 |
+
masked_depth_map, mean_depth = utils.get_masked_depth(depthmap, mask)
|
| 279 |
+
debugLog(f"Debug - Object {idx}: Masked depth min/max: {masked_depth_map.min()}, {masked_depth_map.max()}, Mean depth: {mean_depth}")
|
| 280 |
+
|
| 281 |
+
# Handle invalid or NaN mean_depth
|
| 282 |
+
if (np.isnan(mean_depth) or not isinstance(mean_depth, (int, float)) or mean_depth <= 0):
|
| 283 |
+
debugLog(f"Warning: Invalid mean depth ({mean_depth}) for Object {idx}. Using default depth of 1.0...")
|
| 284 |
+
mean_depth = 1.0 # Fallback to 1.0 meter
|
| 285 |
|
| 286 |
|
| 287 |
# Scale from 1536x1024 to 1512x1008, ensuring values fit within bounds
|
|
|
|
| 322 |
"vertices": get_box_vertices([x1, y1, x2, y2])
|
| 323 |
},
|
| 324 |
"center_2d": center, # Add 2D center in screen space
|
| 325 |
+
"distance": float(mean_depth), # Depth in meters
|
| 326 |
+
#"distance": depth_value, # Depth in meters
|
| 327 |
"color": color_rgb,
|
| 328 |
"confidence": float(confidence)
|
| 329 |
|