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
Heatmap(**kwargs)
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
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
heatmap_effect
heatmap_effect(box)
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
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
process
process(im0)
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 |
Source code in ultralytics/solutions/heatmap.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|