Apply colormap to imagecanvas
This commit is contained in:
parent
648f17bc42
commit
5b93c842df
1 changed files with 9 additions and 6 deletions
15
head_pose.py
15
head_pose.py
|
@ -13,6 +13,7 @@ import seaborn as sns
|
||||||
|
|
||||||
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
|
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
|
||||||
from matplotlib.figure import Figure
|
from matplotlib.figure import Figure
|
||||||
|
from matplotlib import cm
|
||||||
import sys
|
import sys
|
||||||
if sys.version_info[0] < 3:
|
if sys.version_info[0] < 3:
|
||||||
import Tkinter as Tk
|
import Tkinter as Tk
|
||||||
|
@ -38,7 +39,7 @@ screenDrawCorners = np.array([[10,60], [90, 60], [10, 110], [90, 110]])
|
||||||
# metrics matrix
|
# metrics matrix
|
||||||
metricsSize = [1920,1080]
|
metricsSize = [1920,1080]
|
||||||
dataframe = pd.DataFrame(columns=['x','y'])
|
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]])
|
screenDrawCorners = np.array([[0,0], [1919,0], [0, 1079], [1919,1079]])
|
||||||
|
|
||||||
def create_perspective_transform_matrix(src, dst):
|
def create_perspective_transform_matrix(src, dst):
|
||||||
|
@ -337,7 +338,7 @@ while True:
|
||||||
tm4 = 0
|
tm4 = 0
|
||||||
else:
|
else:
|
||||||
tm1 = time.time()
|
tm1 = time.time()
|
||||||
newMetrics = np.zeros(metricsSize)
|
newMetrics = np.zeros((metricsSize[1], metricsSize[0]))
|
||||||
tm2 = time.time()
|
tm2 = time.time()
|
||||||
for point in currentPoints:
|
for point in currentPoints:
|
||||||
# check if within coordinates:
|
# check if within coordinates:
|
||||||
|
@ -355,9 +356,9 @@ while True:
|
||||||
targetInt = (int(targetPoint[0]), int(targetPoint[1]))
|
targetInt = (int(targetPoint[0]), int(targetPoint[1]))
|
||||||
# check if point fits on screen:
|
# check if point fits on screen:
|
||||||
# if so, measure it
|
# 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)
|
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
|
# after we collected all new metrics, blur them foor smoothness
|
||||||
# and add to all metrics collected
|
# and add to all metrics collected
|
||||||
tm3 = time.time()
|
tm3 = time.time()
|
||||||
|
@ -377,7 +378,9 @@ while True:
|
||||||
|
|
||||||
# update the heatmap output
|
# update the heatmap output
|
||||||
tm21 = time.time()
|
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()
|
tm22 = time.time()
|
||||||
logger.debug("Max normalised metrics: %f", np.max(normalisedMetrics))
|
logger.debug("Max normalised metrics: %f", np.max(normalisedMetrics))
|
||||||
# print(normalisedMetrics)
|
# print(normalisedMetrics)
|
||||||
|
@ -397,7 +400,7 @@ while True:
|
||||||
te4 = time.time()
|
te4 = time.time()
|
||||||
axes.clear()
|
axes.clear()
|
||||||
if(len(dataframe) > 2):
|
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()
|
canvas.draw()
|
||||||
windowRoot.update()
|
windowRoot.update()
|
||||||
te5 = time.time()
|
te5 = time.time()
|
||||||
|
|
Loading…
Reference in a new issue