feat: update tracking working
This commit is contained in:
parent
9e4c23c75c
commit
255be78d43
2 changed files with 62 additions and 97 deletions
|
@ -146,6 +146,17 @@ class TrackingPipelineIntegration:
|
||||||
persist=True
|
persist=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Debug: Log raw detection results
|
||||||
|
if tracking_results and hasattr(tracking_results, 'detections'):
|
||||||
|
raw_detections = len(tracking_results.detections)
|
||||||
|
if raw_detections > 0:
|
||||||
|
class_names = [detection.class_name for detection in tracking_results.detections]
|
||||||
|
logger.info(f"[DEBUG] Raw detections: {raw_detections}, classes: {class_names}")
|
||||||
|
else:
|
||||||
|
logger.debug(f"[DEBUG] No raw detections found")
|
||||||
|
else:
|
||||||
|
logger.debug(f"[DEBUG] No tracking results or detections attribute")
|
||||||
|
|
||||||
# Process tracking results
|
# Process tracking results
|
||||||
tracked_vehicles = self.tracker.process_detections(
|
tracked_vehicles = self.tracker.process_detections(
|
||||||
tracking_results,
|
tracking_results,
|
||||||
|
|
|
@ -130,33 +130,29 @@ class VehicleTracker:
|
||||||
logger.debug(f"Removing expired track {track_id}")
|
logger.debug(f"Removing expired track {track_id}")
|
||||||
del self.tracked_vehicles[track_id]
|
del self.tracked_vehicles[track_id]
|
||||||
|
|
||||||
# Process new detections
|
# Process new detections from InferenceResult
|
||||||
if hasattr(results, 'boxes') and results.boxes is not None:
|
if hasattr(results, 'detections') and results.detections:
|
||||||
boxes = results.boxes
|
# Process detections from InferenceResult
|
||||||
|
for detection in results.detections:
|
||||||
# Check if tracking is available
|
# Skip if confidence is too low
|
||||||
if hasattr(boxes, 'id') and boxes.id is not None:
|
if detection.confidence < self.min_confidence:
|
||||||
# Process tracked objects
|
|
||||||
for i, box in enumerate(boxes):
|
|
||||||
# Get tracking ID
|
|
||||||
track_id = int(boxes.id[i].item()) if boxes.id[i] is not None else None
|
|
||||||
if track_id is None:
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Get class and confidence
|
|
||||||
cls_id = int(box.cls.item())
|
|
||||||
confidence = float(box.conf.item())
|
|
||||||
|
|
||||||
# Check if class is in trigger classes
|
# Check if class is in trigger classes
|
||||||
class_name = results.names[cls_id] if hasattr(results, 'names') else str(cls_id)
|
if detection.class_name not in self.trigger_classes:
|
||||||
if class_name not in self.trigger_classes and confidence < self.min_confidence:
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Get bounding box
|
# Use track_id if available, otherwise generate one
|
||||||
x1, y1, x2, y2 = box.xyxy[0].cpu().numpy().astype(int)
|
track_id = detection.track_id if detection.track_id is not None else self.next_track_id
|
||||||
bbox = (x1, y1, x2, y2)
|
if detection.track_id is None:
|
||||||
|
self.next_track_id += 1
|
||||||
|
|
||||||
|
# Get bounding box from Detection object
|
||||||
|
x1, y1, x2, y2 = detection.bbox
|
||||||
|
bbox = (int(x1), int(y1), int(x2), int(y2))
|
||||||
|
|
||||||
# Update or create tracked vehicle
|
# Update or create tracked vehicle
|
||||||
|
confidence = detection.confidence
|
||||||
if track_id in self.tracked_vehicles:
|
if track_id in self.tracked_vehicles:
|
||||||
# Update existing track
|
# Update existing track
|
||||||
vehicle = self.tracked_vehicles[track_id]
|
vehicle = self.tracked_vehicles[track_id]
|
||||||
|
@ -193,48 +189,6 @@ class VehicleTracker:
|
||||||
logger.info(f"New vehicle tracked: ID={track_id}, display={display_id}")
|
logger.info(f"New vehicle tracked: ID={track_id}, display={display_id}")
|
||||||
|
|
||||||
active_tracks.append(self.tracked_vehicles[track_id])
|
active_tracks.append(self.tracked_vehicles[track_id])
|
||||||
else:
|
|
||||||
# No tracking available, process as detections only
|
|
||||||
logger.debug("No tracking IDs available, processing as detections only")
|
|
||||||
for i, box in enumerate(boxes):
|
|
||||||
cls_id = int(box.cls.item())
|
|
||||||
confidence = float(box.conf.item())
|
|
||||||
|
|
||||||
# Check confidence threshold
|
|
||||||
if confidence < self.min_confidence:
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Get bounding box
|
|
||||||
x1, y1, x2, y2 = box.xyxy[0].cpu().numpy().astype(int)
|
|
||||||
bbox = (x1, y1, x2, y2)
|
|
||||||
center = ((x1 + x2) / 2, (y1 + y2) / 2)
|
|
||||||
|
|
||||||
# Try to match with existing tracks by position
|
|
||||||
matched_track = self._find_closest_track(center)
|
|
||||||
|
|
||||||
if matched_track:
|
|
||||||
matched_track.update_position(bbox, confidence)
|
|
||||||
matched_track.display_id = display_id
|
|
||||||
active_tracks.append(matched_track)
|
|
||||||
else:
|
|
||||||
# Create new track with generated ID
|
|
||||||
track_id = self.next_track_id
|
|
||||||
self.next_track_id += 1
|
|
||||||
|
|
||||||
vehicle = TrackedVehicle(
|
|
||||||
track_id=track_id,
|
|
||||||
first_seen=current_time,
|
|
||||||
last_seen=current_time,
|
|
||||||
display_id=display_id,
|
|
||||||
confidence=confidence,
|
|
||||||
bbox=bbox,
|
|
||||||
center=center,
|
|
||||||
total_frames=1
|
|
||||||
)
|
|
||||||
vehicle.last_position_history.append(center)
|
|
||||||
self.tracked_vehicles[track_id] = vehicle
|
|
||||||
active_tracks.append(vehicle)
|
|
||||||
logger.info(f"New vehicle detected (no tracking): ID={track_id}")
|
|
||||||
|
|
||||||
return active_tracks
|
return active_tracks
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue