Manvikk commited on
Commit
7ca2086
·
verified ·
1 Parent(s): 9ea7720

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -0
app.py CHANGED
@@ -149,6 +149,7 @@ def process_image(job_id, image_path, object_type, multiplier):
149
  # We assume the printed marker is 5 cm x 5 cm.
150
  marker_real_width_cm = 5.0
151
  conversion_factor = None
 
152
  try:
153
  # Convert to grayscale
154
  gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
@@ -198,12 +199,30 @@ def process_image(job_id, image_path, object_type, multiplier):
198
  print("DEBUG: Detected marker with ID", ids[selected_index][0],
199
  "Average side length (px):", avg_side_length,
200
  "Conversion factor:", conversion_factor)
 
 
 
 
 
 
201
  else:
202
  print("DEBUG: No markers detected in ArUco detection.")
203
  except Exception as e:
204
  print("DEBUG: Exception during ArUco detection:", e)
205
  conversion_factor = None
206
 
 
 
 
 
 
 
 
 
 
 
 
 
207
  for pred in box_detections:
208
  x1, y1, x2, y2 = pred["box"]
209
  label = pred["class"]
 
149
  # We assume the printed marker is 5 cm x 5 cm.
150
  marker_real_width_cm = 5.0
151
  conversion_factor = None
152
+ marker_bbox = None
153
  try:
154
  # Convert to grayscale
155
  gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
 
199
  print("DEBUG: Detected marker with ID", ids[selected_index][0],
200
  "Average side length (px):", avg_side_length,
201
  "Conversion factor:", conversion_factor)
202
+ # Compute marker bounding box from the detected corners
203
+ marker_bbox = (int(np.min(marker_corners[:,0])),
204
+ int(np.min(marker_corners[:,1])),
205
+ int(np.max(marker_corners[:,0])),
206
+ int(np.max(marker_corners[:,1])))
207
+ print("DEBUG: Marker bounding box:", marker_bbox)
208
  else:
209
  print("DEBUG: No markers detected in ArUco detection.")
210
  except Exception as e:
211
  print("DEBUG: Exception during ArUco detection:", e)
212
  conversion_factor = None
213
 
214
+ # --- Filter out the marker from box detections ---
215
+ if marker_bbox is not None:
216
+ print("DEBUG: Filtering out aruco marker detection from box detections.")
217
+ filtered_box_detections = []
218
+ for detection in box_detections:
219
+ iou_val = compute_iou(detection["box"], marker_bbox)
220
+ print("DEBUG: IoU with marker:", iou_val)
221
+ if iou_val < 0.5:
222
+ filtered_box_detections.append(detection)
223
+ box_detections = filtered_box_detections
224
+
225
+ # --- Draw remaining box detections and compute measurements ---
226
  for pred in box_detections:
227
  x1, y1, x2, y2 = pred["box"]
228
  label = pred["class"]