mlbench123 commited on
Commit
62a7547
·
verified ·
1 Parent(s): 1871e7a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -7
app.py CHANGED
@@ -128,7 +128,8 @@ class DroneDetectionPipeline:
128
 
129
  # Choose color: Red for detection, Blue for tracking
130
  color = (0, 0, 255) if not is_tracking else (255, 0, 0)
131
- label_text = f"Drone (Det)" if not is_tracking else f"Drone (Track)"
 
132
 
133
  if confidence is not None and not is_tracking:
134
  label_text = f"Drone {confidence:.2f}"
@@ -208,28 +209,33 @@ class DroneDetectionPipeline:
208
  low_conf_detections.append((x1, y1, x2, y2, confidence))
209
 
210
  if high_conf_detections:
211
- # Use high confidence detection - normal detection display
212
  largest_detection = max(high_conf_detections, key=lambda d: (d[2]-d[0]) * (d[3]-d[1]))
213
  x1, y1, x2, y2, conf = largest_detection
214
  detection_bbox = (x1, y1, x2-x1, y2-y1)
215
 
216
  frame_processed = self._draw_detection(frame_processed, (x1, y1, x2, y2), None, False)
217
  self._initialize_tracker(frame, detection_bbox)
 
218
  detection_count += 1
219
 
220
- elif low_conf_detections and self.last_detection_bbox is not None:
221
- # Use low confidence detection for tracking only
222
  largest_low_conf = max(low_conf_detections, key=lambda d: (d[2]-d[0]) * (d[3]-d[1]))
223
  x1, y1, x2, y2, conf = largest_low_conf
224
  tracking_bbox = (x1, y1, x2-x1, y2-y1)
225
 
226
- # Update last known position and show as tracking
 
 
 
 
227
  self.last_detection_bbox = tracking_bbox
228
  frame_processed = self._draw_detection(frame_processed, (x1, y1, x2, y2), None, True)
229
  tracking_count += 1
230
 
231
- elif self.tracking_active and self.tracker is not None:
232
- # Use CSRT tracker when no detections
233
  success, tracking_bbox = self.tracker.update(frame)
234
 
235
  if success:
@@ -237,6 +243,7 @@ class DroneDetectionPipeline:
237
  self.last_detection_bbox = tracking_bbox
238
  frame_processed = self._draw_detection(frame_processed, (x, y, x+w, y+h), None, True)
239
  tracking_count += 1
 
240
  else:
241
  # Tracking failed - use last known position
242
  if self.last_detection_bbox is not None:
 
128
 
129
  # Choose color: Red for detection, Blue for tracking
130
  color = (0, 0, 255) if not is_tracking else (255, 0, 0)
131
+ # label_text = f"Drone (Det)" if not is_tracking else f"Drone (Track)"
132
+ label_text = f"Drone"
133
 
134
  if confidence is not None and not is_tracking:
135
  label_text = f"Drone {confidence:.2f}"
 
209
  low_conf_detections.append((x1, y1, x2, y2, confidence))
210
 
211
  if high_conf_detections:
212
+ # High confidence detection - show red box
213
  largest_detection = max(high_conf_detections, key=lambda d: (d[2]-d[0]) * (d[3]-d[1]))
214
  x1, y1, x2, y2, conf = largest_detection
215
  detection_bbox = (x1, y1, x2-x1, y2-y1)
216
 
217
  frame_processed = self._draw_detection(frame_processed, (x1, y1, x2, y2), None, False)
218
  self._initialize_tracker(frame, detection_bbox)
219
+ self.has_had_detection = True
220
  detection_count += 1
221
 
222
+ elif low_conf_detections and self.has_had_detection:
223
+ # Low confidence detection - show blue tracking box
224
  largest_low_conf = max(low_conf_detections, key=lambda d: (d[2]-d[0]) * (d[3]-d[1]))
225
  x1, y1, x2, y2, conf = largest_low_conf
226
  tracking_bbox = (x1, y1, x2-x1, y2-y1)
227
 
228
+ # Update tracker with low confidence detection
229
+ if self.tracker is not None:
230
+ self.tracker.init(frame, tracking_bbox)
231
+ self.tracking_active = True
232
+
233
  self.last_detection_bbox = tracking_bbox
234
  frame_processed = self._draw_detection(frame_processed, (x1, y1, x2, y2), None, True)
235
  tracking_count += 1
236
 
237
+ elif self.has_had_detection and self.tracker is not None:
238
+ # No detections - use CSRT tracker
239
  success, tracking_bbox = self.tracker.update(frame)
240
 
241
  if success:
 
243
  self.last_detection_bbox = tracking_bbox
244
  frame_processed = self._draw_detection(frame_processed, (x, y, x+w, y+h), None, True)
245
  tracking_count += 1
246
+ self.tracking_active = True
247
  else:
248
  # Tracking failed - use last known position
249
  if self.last_detection_bbox is not None: