Video-Summary/Application/HeatMap.py

27 lines
867 B
Python
Raw Normal View History

2022-01-09 11:25:22 +00:00
import numpy as np
from matplotlib import pyplot as plt
2022-01-09 19:25:44 +00:00
2022-01-09 11:25:22 +00:00
class HeatMap:
2022-01-09 19:25:44 +00:00
def __init__(self, x, y, contours, resizeFactor=1):
2022-01-09 11:25:22 +00:00
self.imageBW = np.zeros(shape=[y, x, 3], dtype=np.float64)
self._resizeFactor = resizeFactor
self._createImage(contours)
def _createImage(self, contours):
for contour in contours:
for x, y, w, h in contour:
2022-01-09 19:25:44 +00:00
x, y, w, h = (
x * self._resizeFactor,
y * self._resizeFactor,
w * self._resizeFactor,
h * self._resizeFactor,
)
self.imageBW[int(y) : int(y + h), int(x) : int(x + w)] += 1
2022-01-09 11:25:22 +00:00
2022-01-09 19:25:44 +00:00
self.imageBW = np.nan_to_num(self.imageBW / self.imageBW.sum(axis=1)[:, np.newaxis], 0)
2022-01-09 11:25:22 +00:00
def showImage(self):
2022-01-09 19:25:44 +00:00
plt.imshow(self.imageBW * 255)
2022-01-09 11:25:22 +00:00
plt.show()