Manvikk commited on
Commit
d95876a
·
verified ·
1 Parent(s): d39a89a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -2
app.py CHANGED
@@ -144,21 +144,27 @@ def process_image(job_id, image_path, object_type, multiplier):
144
  except Exception as e:
145
  continue
146
 
147
- # You might experiment with the NMS threshold further if needed.
148
  box_detections = custom_nms(processed_preds, iou_threshold=0.7)
149
  jobs[job_id]['progress'] = 60
150
 
151
  # (Optional) Detect ArUco marker for measurement.
152
- marker_real_width_cm = 10.0
 
 
153
  try:
154
  gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
 
155
  aruco_dict = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_6X6_250)
 
 
156
  if hasattr(cv2.aruco, 'DetectorParameters_create'):
157
  aruco_params = cv2.aruco.DetectorParameters_create()
158
  else:
159
  aruco_params = cv2.aruco.DetectorParameters()
160
  corners, ids, _ = cv2.aruco.detectMarkers(gray, aruco_dict, parameters=aruco_params)
161
  if ids is not None and len(corners) > 0:
 
162
  marker_corners = corners[0].reshape((4, 2))
163
  cv2.aruco.drawDetectedMarkers(image, corners, ids)
164
  side_lengths = []
 
144
  except Exception as e:
145
  continue
146
 
147
+ # Increase the NMS IoU threshold to 0.7 so that touching boxes are less likely to be suppressed.
148
  box_detections = custom_nms(processed_preds, iou_threshold=0.7)
149
  jobs[job_id]['progress'] = 60
150
 
151
  # (Optional) Detect ArUco marker for measurement.
152
+ # Set the real-world width of your marker in centimeters.
153
+ # For a marker that is 5cm x 5cm, use 5.0.
154
+ marker_real_width_cm = 5.0
155
  try:
156
  gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
157
+ # Use a predefined dictionary. You can try DICT_6X6_250 (or DICT_4X4_50 if you prefer).
158
  aruco_dict = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_6X6_250)
159
+ # Alternatively:
160
+ # aruco_dict = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_4X4_50)
161
  if hasattr(cv2.aruco, 'DetectorParameters_create'):
162
  aruco_params = cv2.aruco.DetectorParameters_create()
163
  else:
164
  aruco_params = cv2.aruco.DetectorParameters()
165
  corners, ids, _ = cv2.aruco.detectMarkers(gray, aruco_dict, parameters=aruco_params)
166
  if ids is not None and len(corners) > 0:
167
+ # Use the first detected marker as reference.
168
  marker_corners = corners[0].reshape((4, 2))
169
  cv2.aruco.drawDetectedMarkers(image, corners, ids)
170
  side_lengths = []