Alessio Grancini
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -260,10 +260,16 @@ def get_detection_data(image_data):
|
|
260 |
# Unpack all 6 values
|
261 |
cls_id, cls_name, center, mask, color_bgr, confidence = obj
|
262 |
x1, y1, x2, y2 = get_bbox_from_mask(mask)
|
|
|
263 |
depth_value = depth_at_center(depthmap, [x1, y1, x2, y2])
|
|
|
|
|
|
|
264 |
|
265 |
-
#
|
266 |
-
|
|
|
|
|
267 |
|
268 |
# Scale from 1536x1024 to 1512x1008, ensuring values fit within bounds
|
269 |
scale_x = 1512 / 1536 # Width scaling factor
|
@@ -314,7 +320,7 @@ def get_detection_data(image_data):
|
|
314 |
"vertices": scaled_vertices
|
315 |
},
|
316 |
"center_2d": scaled_center, # Use scaled center
|
317 |
-
"distance": depth_value, #
|
318 |
"color": color_rgb,
|
319 |
"confidence": float(confidence)
|
320 |
|
|
|
260 |
# Unpack all 6 values
|
261 |
cls_id, cls_name, center, mask, color_bgr, confidence = obj
|
262 |
x1, y1, x2, y2 = get_bbox_from_mask(mask)
|
263 |
+
|
264 |
depth_value = depth_at_center(depthmap, [x1, y1, x2, y2])
|
265 |
+
|
266 |
+
# Debug: Log original center and vertices (1536x1024)
|
267 |
+
print(f"Debug - Object {idx}: Original Center = {center}, Original Vertices = {get_box_vertices([x1, y1, x2, y2])}")
|
268 |
|
269 |
+
# Handle invalid or NaN depth values
|
270 |
+
if depth_value is None or np.isnan(depth_value) or not isinstance(depth_value, (int, float)) or depth_value <= 0:
|
271 |
+
print(f"Warning: Invalid depth value ({depth_value}) for Object {idx}. Using default depth of 1.0...")
|
272 |
+
depth_value = 1.0 # Default to 1.0 if depth is invalid or NaN
|
273 |
|
274 |
# Scale from 1536x1024 to 1512x1008, ensuring values fit within bounds
|
275 |
scale_x = 1512 / 1536 # Width scaling factor
|
|
|
320 |
"vertices": scaled_vertices
|
321 |
},
|
322 |
"center_2d": scaled_center, # Use scaled center
|
323 |
+
"distance": float(depth_value), # Ensure depth is a float, not NaN
|
324 |
"color": color_rgb,
|
325 |
"confidence": float(confidence)
|
326 |
|