From fceaa4003871479e047f607ebb09356a95475e33 Mon Sep 17 00:00:00 2001 From: Muhammad Rizwan Munawar Date: Fri, 4 Oct 2024 02:32:55 +0500 Subject: [PATCH] Remove unused arguments in Ultralytics `heatmaps` (#16667) Co-authored-by: UltralyticsAssistant Co-authored-by: Glenn Jocher --- docs/en/guides/heatmaps.md | 9 --------- ultralytics/solutions/heatmap.py | 14 ++------------ 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/docs/en/guides/heatmaps.md b/docs/en/guides/heatmaps.md index 7d5aad6c2b..4e0a665fa0 100644 --- a/docs/en/guides/heatmaps.md +++ b/docs/en/guides/heatmaps.md @@ -34,11 +34,6 @@ A heatmap generated with [Ultralytics YOLO11](https://github.com/ultralytics/ult | ![Ultralytics YOLO11 Transportation Heatmap](https://github.com/ultralytics/docs/releases/download/0/ultralytics-yolov8-transportation-heatmap.avif) | ![Ultralytics YOLO11 Retail Heatmap](https://github.com/ultralytics/docs/releases/download/0/ultralytics-yolov8-retail-heatmap.avif) | | Ultralytics YOLO11 Transportation Heatmap | Ultralytics YOLO11 Retail Heatmap | -!!! tip "Heatmap Configuration" - - - `heatmap_alpha`: Ensure this value is within the range (0.0 - 1.0). - - `decay_factor`: Used for removing heatmap after an object is no longer in the frame, its value should also be in the range (0.0 - 1.0). - !!! example "Heatmaps using Ultralytics YOLO11 Example" === "Heatmap" @@ -274,10 +269,7 @@ A heatmap generated with [Ultralytics YOLO11](https://github.com/ultralytics/ult | Name | Type | Default | Description | | ------------------ | ---------------- | ------------------ | ----------------------------------------------------------------- | | `names` | `list` | `None` | Dictionary of class names. | -| `imw` | `int` | `0` | Image width. | -| `imh` | `int` | `0` | Image height. | | `colormap` | `int` | `cv2.COLORMAP_JET` | Colormap to use for the heatmap. | -| `heatmap_alpha` | `float` | `0.5` | Alpha blending value for heatmap overlay. | | `view_img` | `bool` | `False` | Whether to display the image with the heatmap overlay. | | `view_in_counts` | `bool` | `True` | Whether to display the count of objects entering the region. | | `view_out_counts` | `bool` | `True` | Whether to display the count of objects exiting the region. | @@ -288,7 +280,6 @@ A heatmap generated with [Ultralytics YOLO11](https://github.com/ultralytics/ult | `region_thickness` | `int` | `5` | Thickness of the region line. | | `line_dist_thresh` | `int` | `15` | Distance threshold for line-based counting. | | `line_thickness` | `int` | `2` | Thickness of the lines used in drawing. | -| `decay_factor` | `float` | `0.99` | Decay factor for the heatmap to reduce intensity over time. | | `shape` | `str` | `"circle"` | Shape of the heatmap blobs ('circle' or 'rect'). | ### Arguments `model.track` diff --git a/ultralytics/solutions/heatmap.py b/ultralytics/solutions/heatmap.py index 728b167bc8..79e37b9c2a 100644 --- a/ultralytics/solutions/heatmap.py +++ b/ultralytics/solutions/heatmap.py @@ -19,10 +19,7 @@ class Heatmap: def __init__( self, names, - imw=0, - imh=0, colormap=cv2.COLORMAP_JET, - heatmap_alpha=0.5, view_img=False, view_in_counts=True, view_out_counts=True, @@ -33,7 +30,6 @@ class Heatmap: region_thickness=5, line_dist_thresh=15, line_thickness=2, - decay_factor=0.99, shape="circle", ): """Initializes the heatmap class with default values for Visual, Image, track, count and heatmap parameters.""" @@ -46,8 +42,6 @@ class Heatmap: self.names = names # Classes names # Image information - self.imw = imw - self.imh = imh self.im0 = None self.tf = line_thickness self.view_in_counts = view_in_counts @@ -56,7 +50,6 @@ class Heatmap: # Heatmap colormap and heatmap np array self.colormap = colormap self.heatmap = None - self.heatmap_alpha = heatmap_alpha # Predict/track information self.boxes = [] @@ -79,9 +72,6 @@ class Heatmap: self.count_bg_color = count_bg_color self.cls_txtdisplay_gap = 50 - # Decay factor - self.decay_factor = decay_factor - # Check if environment supports imshow self.env_check = check_imshow(warn=True) @@ -133,7 +123,7 @@ class Heatmap: self.heatmap = np.zeros((int(self.im0.shape[0]), int(self.im0.shape[1])), dtype=np.float32) self.initialized = True - self.heatmap *= self.decay_factor # decay factor + self.heatmap *= 0.99 # decay factor self.extract_results(tracks) self.annotator = Annotator(self.im0, self.tf, None) @@ -239,7 +229,7 @@ class Heatmap: # Normalize, apply colormap to heatmap and combine with original image heatmap_normalized = cv2.normalize(self.heatmap, None, 0, 255, cv2.NORM_MINMAX) heatmap_colored = cv2.applyColorMap(heatmap_normalized.astype(np.uint8), self.colormap) - self.im0 = cv2.addWeighted(self.im0, 1 - self.heatmap_alpha, heatmap_colored, self.heatmap_alpha, 0) + self.im0 = cv2.addWeighted(self.im0, 0.5, heatmap_colored, 0.5, 0) if self.env_check and self.view_img: self.display_frames()