Reference for ultralytics/solutions/heatmap.py
Note
This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/solutions/heatmap.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
ultralytics.solutions.heatmap.Heatmap
Bases: ObjectCounter
A class to draw heatmaps in real-time video streams based on object tracks.
This class extends the ObjectCounter class to generate and visualize heatmaps of object movements in video streams. It uses tracked object positions to create a cumulative heatmap effect over time.
Attributes:
Name | Type | Description |
---|---|---|
initialized |
bool
|
Flag indicating whether the heatmap has been initialized. |
colormap |
int
|
OpenCV colormap used for heatmap visualization. |
heatmap |
ndarray
|
Array storing the cumulative heatmap data. |
annotator |
SolutionAnnotator
|
Object for drawing annotations on the image. |
Methods:
Name | Description |
---|---|
heatmap_effect |
Calculate and update the heatmap effect for a given bounding box. |
process |
Generate and apply the heatmap effect to each frame. |
Examples:
>>> from ultralytics.solutions import Heatmap
>>> heatmap = Heatmap(model="yolo11n.pt", colormap=cv2.COLORMAP_JET)
>>> frame = cv2.imread("frame.jpg")
>>> processed_frame = heatmap.process(frame)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Any
|
Keyword arguments passed to the parent ObjectCounter class. |
{}
|
Source code in ultralytics/solutions/heatmap.py
heatmap_effect
Efficiently calculate heatmap area and effect location for applying colormap.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
box
|
List[float]
|
Bounding box coordinates [x0, y0, x1, y1]. |
required |
Source code in ultralytics/solutions/heatmap.py
process
Generate heatmap for each frame using Ultralytics.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
im0
|
ndarray
|
Input image array for processing. |
required |
Returns:
Type | Description |
---|---|
SolutionResults
|
Contains processed image |