Skip to content

Commit

Permalink
Heatmaps bug fix (ultralytics#17634)
Browse files Browse the repository at this point in the history
  • Loading branch information
RizwanMunawar authored Nov 19, 2024
1 parent 35b6fed commit bde3105
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions ultralytics/solutions/heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ def generate_heatmap(self, im0):
self.annotator.draw_region(reg_pts=self.region, color=(104, 0, 123), thickness=self.line_width * 2)
self.store_tracking_history(track_id, box) # Store track history
self.store_classwise_counts(cls) # store classwise counts in dict

current_centroid = ((box[0] + box[2]) / 2, (box[1] + box[3]) / 2)
# Store tracking previous position and perform object counting
prev_position = None
if len(self.track_history[track_id]) > 1:
prev_position = self.track_history[track_id][-2]
self.count_objects(self.track_line, box, track_id, prev_position, cls) # Perform object counting
self.count_objects(current_centroid, track_id, prev_position, cls) # Perform object counting

if self.region is not None:
self.display_counts(im0) # Display the counts on the frame
Expand Down
2 changes: 1 addition & 1 deletion ultralytics/solutions/object_counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def count_objects(self, current_centroid, track_id, prev_position, cls):
>>> track_id = 1
>>> prev_position = (120, 220)
>>> cls = 0
>>> counter.count_objects(track_line, box, track_id, prev_position, cls)
>>> counter.count_objects(current_centroid, track_id, prev_position, cls)
"""
if prev_position is None or track_id in self.counted_ids:
return
Expand Down

0 comments on commit bde3105

Please sign in to comment.