Apply colormap to imagecanvas

This commit is contained in:
Ruben 2018-04-29 15:48:07 +02:00
parent 648f17bc42
commit 5b93c842df

View file

@ -13,6 +13,7 @@ import seaborn as sns
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
from matplotlib import cm
import sys
if sys.version_info[0] < 3:
import Tkinter as Tk
@ -38,7 +39,7 @@ screenDrawCorners = np.array([[10,60], [90, 60], [10, 110], [90, 110]])
# metrics matrix
metricsSize = [1920,1080]
dataframe = pd.DataFrame(columns=['x','y'])
metrics = np.zeros(metricsSize)
metrics = np.zeros((metricsSize[1], metricsSize[0])) # (y, x)
screenDrawCorners = np.array([[0,0], [1919,0], [0, 1079], [1919,1079]])
def create_perspective_transform_matrix(src, dst):
@ -337,7 +338,7 @@ while True:
tm4 = 0
else:
tm1 = time.time()
newMetrics = np.zeros(metricsSize)
newMetrics = np.zeros((metricsSize[1], metricsSize[0]))
tm2 = time.time()
for point in currentPoints:
# check if within coordinates:
@ -355,9 +356,9 @@ while True:
targetInt = (int(targetPoint[0]), int(targetPoint[1]))
# check if point fits on screen:
# if so, measure it
if targetInt[0] >= 0 and targetInt[1] >= 0 and targetInt[0] < metricsSize[0] and targetInt[1] < metricsSize[1]:
if targetInt[0] >= 0 and targetInt[1] >= 0 and targetInt[0] < metricsSize[1] and targetInt[1] < metricsSize[0]:
dataframe = dataframe.append({'x':targetInt[0],'y':targetInt[1]}, ignore_index=True)
newMetrics[targetInt[0],targetInt[1]] += 1
newMetrics[targetInt[1],targetInt[0]] += 1
# after we collected all new metrics, blur them foor smoothness
# and add to all metrics collected
tm3 = time.time()
@ -377,7 +378,9 @@ while True:
# update the heatmap output
tm21 = time.time()
normalisedMetrics = metrics / (np.max(metrics)/255)
normalisedMetrics = metrics / (np.max(metrics))
# convert to colormap, thanks to: https://stackoverflow.com/a/10967471
normalisedMetrics = np.uint8(cm.plasma(normalisedMetrics)*255)
tm22 = time.time()
logger.debug("Max normalised metrics: %f", np.max(normalisedMetrics))
# print(normalisedMetrics)
@ -397,7 +400,7 @@ while True:
te4 = time.time()
axes.clear()
if(len(dataframe) > 2):
g = sns.kdeplot(dataframe['x'], dataframe['y'],ax=axes, n_levels=30, shade=True, cmap="rainbow")
g = sns.kdeplot(dataframe['x'], dataframe['y'],ax=axes, n_levels=30, shade=True, cmap=cm.rainbow)
canvas.draw()
windowRoot.update()
te5 = time.time()