Draw image and video heatmaps in python
pip install heatmappy
- matplotlib
- moviepy
- numpy
- Pillow
- PySide (optional: up to ~20% faster than Pillow alone)
from heatmappy import Heatmapper from PIL import Image example_points = [(100, 20), (120, 25), (200, 50), (60, 300), (170, 250)] example_img_path = 'cat.jpg' example_img = Image.open(example_img_path)
heatmapper = Heatmapper() heatmap = heatmapper.heatmap_on_img(example_points, example_img) heatmap.save('heatmap.png')
heatmapper = Heatmapper(opacity=0.9, colours='reveal') heatmap = heatmapper.heatmap_on_img_path(example_points, example_img_path) heatmap.save('heatmap.png')
Input points are in the form (x, y, t) where t is in milliseconds.
example_vid = os.path.join('assets', 'some_video.mp4') example_points = [(100, 100, 25), (112, 92, 67), (17, 100, 36)] img_heatmapper = Heatmapper() video_heatmapper = VideoHeatmapper(img_heatmapper) heatmap_video = video_heatmapper.heatmap_on_video_path( video_path=example_vid, points=example_points ) heatmap_video.write_videofile('out.mp4', bitrate="5000k", fps=24)
The following options are available (shown with their default values):
heatmapper = Heatmapper( point_diameter=50, # the size of each point to be drawn point_strength=0.2, # the strength, between 0 and 1, of each point to be drawn opacity=0.65, # the opacity of the heatmap layer colours='default', # 'default' or 'reveal' # OR a matplotlib LinearSegmentedColorMap object # OR the path to a horizontal scale image grey_heatmapper='PIL' # The object responsible for drawing the points # Pillow used by default, 'PySide' option available if installed ) video_heatmapper = VideoHeatmapper( heatmapper # the img heatmapper to use (like the heatmapper above, for example) )
- Can specify different point size for each point plotted.
MIT License.