Alessio Grancini
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -264,6 +264,17 @@ def get_detection_data(image_data):
|
|
264 |
|
265 |
# Debug: Log center and vertices to verify resolution
|
266 |
print(f"Debug - Object {idx}: Center = {center}, Vertices = {get_box_vertices([x1, y1, x2, y2])}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
267 |
|
268 |
# Convert BGR to RGB
|
269 |
color_rgb = (int(color_bgr[2]), int(color_bgr[1]), int(color_bgr[0]))
|
@@ -279,17 +290,28 @@ def get_detection_data(image_data):
|
|
279 |
#"color": color_rgb,
|
280 |
#"confidence": float(confidence)
|
281 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
282 |
detections.append({
|
283 |
"class_id": cls_id,
|
284 |
"class_name": cls_name,
|
285 |
"bounding_box": {
|
286 |
-
"vertices":
|
287 |
},
|
288 |
-
"center_2d":
|
289 |
"distance": depth_value, # Depth in meters
|
290 |
"color": color_rgb,
|
291 |
"confidence": float(confidence)
|
292 |
-
|
293 |
})
|
294 |
|
295 |
response = {
|
|
|
264 |
|
265 |
# Debug: Log center and vertices to verify resolution
|
266 |
print(f"Debug - Object {idx}: Center = {center}, Vertices = {get_box_vertices([x1, y1, x2, y2])}")
|
267 |
+
|
268 |
+
# Scale from 1536x1024 to 1512x1008
|
269 |
+
scale_x = 1512 / 1536 # Width scaling factor
|
270 |
+
scale_y = 1008 / 1024 # Height scaling factor
|
271 |
+
|
272 |
+
# Scale center and vertices to 1512x1008
|
273 |
+
scaled_center = (int(center[0] * scale_x), int(center[1] * scale_y))
|
274 |
+
scaled_vertices = [[int(x * scale_x), int(y * scale_y)] for x, y in get_box_vertices([x1, y1, x2, y2])]
|
275 |
+
|
276 |
+
# Debug: Log scaled center and vertices
|
277 |
+
print(f"Debug - Object {idx}: Scaled Center = {scaled_center}, Scaled Vertices = {scaled_vertices}")
|
278 |
|
279 |
# Convert BGR to RGB
|
280 |
color_rgb = (int(color_bgr[2]), int(color_bgr[1]), int(color_bgr[0]))
|
|
|
290 |
#"color": color_rgb,
|
291 |
#"confidence": float(confidence)
|
292 |
|
293 |
+
#detections.append({
|
294 |
+
#"class_id": cls_id,
|
295 |
+
#"class_name": cls_name,
|
296 |
+
#"bounding_box": {
|
297 |
+
# "vertices": get_box_vertices([x1, y1, x2, y2])
|
298 |
+
#},
|
299 |
+
#"center_2d": center, # Add 2D center in screen space
|
300 |
+
#"distance": depth_value, # Depth in meters
|
301 |
+
#"color": color_rgb,
|
302 |
+
#"confidence": float(confidence)
|
303 |
+
|
304 |
detections.append({
|
305 |
"class_id": cls_id,
|
306 |
"class_name": cls_name,
|
307 |
"bounding_box": {
|
308 |
+
"vertices": scaled_vertices
|
309 |
},
|
310 |
+
"center_2d": scaled_center, # Use scaled center
|
311 |
"distance": depth_value, # Depth in meters
|
312 |
"color": color_rgb,
|
313 |
"confidence": float(confidence)
|
314 |
+
})
|
315 |
})
|
316 |
|
317 |
response = {
|