Alessio Grancini commited on
Commit
4b3d198
·
verified ·
1 Parent(s): 8db3d77

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -11
app.py CHANGED
@@ -277,11 +277,13 @@ def get_detection_data(image_data):
277
  # get model size and confidence threshold
278
  model_size = image_data.get("model_size", "Small - Better performance and less accuracy")
279
  confidence_threshold = image_data.get("confidence_threshold", 0.1) # Default from Lens Studio
 
280
  else:
281
  full_data_url = image_data
282
 
283
  model_size = "Small - Better performance and less accuracy" # Fallback default
284
  confidence_threshold = 0.6 # Fallback default
 
285
 
286
  if not full_data_url:
287
  return {"error": "No base64 data found in input."}
@@ -335,18 +337,31 @@ def get_detection_data(image_data):
335
  # Convert BGR to RGB
336
  color_rgb = (int(color_bgr[2]), int(color_bgr[1]), int(color_bgr[0]))
337
 
338
- detections.append({
339
- "class_id": cls_id,
340
- "class_name": cls_name,
341
- "bounding_box": {
342
- "vertices": get_box_vertices([x1, y1, x2, y2])
343
- },
344
- "center_2d": center,
345
- "distance": float(real_distance),
346
- "color": color_rgb,
347
- "confidence": float(confidence)
348
 
349
- })
 
 
 
 
 
 
 
 
 
 
 
 
 
350
 
351
  response = {
352
  "detections": detections,
 
277
  # get model size and confidence threshold
278
  model_size = image_data.get("model_size", "Small - Better performance and less accuracy")
279
  confidence_threshold = image_data.get("confidence_threshold", 0.1) # Default from Lens Studio
280
+ distance_threshold = image_data.get("distance_threshold", 10.0) # Default to 10 meters
281
  else:
282
  full_data_url = image_data
283
 
284
  model_size = "Small - Better performance and less accuracy" # Fallback default
285
  confidence_threshold = 0.6 # Fallback default
286
+ distance_threshold = 10.0 # Default to 10 meters
287
 
288
  if not full_data_url:
289
  return {"error": "No base64 data found in input."}
 
337
  # Convert BGR to RGB
338
  color_rgb = (int(color_bgr[2]), int(color_bgr[1]), int(color_bgr[0]))
339
 
340
+ # detections.append({
341
+ # "class_id": cls_id,
342
+ # "class_name": cls_name,
343
+ # "bounding_box": {
344
+ # "vertices": get_box_vertices([x1, y1, x2, y2])
345
+ # },
346
+ # "center_2d": center,
347
+ # "distance": float(real_distance),
348
+ # "color": color_rgb,
349
+ # "confidence": float(confidence)
350
 
351
+ #})
352
+ # Filter based on distance threshold
353
+ if real_distance <= distance_threshold:
354
+ detections.append({
355
+ "class_id": cls_id,
356
+ "class_name": cls_name,
357
+ "bounding_box": {"vertices": get_box_vertices([x1, y1, x2, y2])},
358
+ "center_2d": center,
359
+ "distance": float(real_distance),
360
+ "color": color_rgb,
361
+ "confidence": float(confidence)
362
+ })
363
+ else:
364
+ print(f"Debug - Object {idx} filtered out: Distance {real_distance} exceeds threshold {distance_threshold}")
365
 
366
  response = {
367
  "detections": detections,