Changes in output
This commit is contained in:
parent
d6e54cf59a
commit
02627cf897
1 changed files with 41 additions and 26 deletions
67
head_pose.py
67
head_pose.py
|
@ -101,8 +101,11 @@ screenDrawCorners = np.array([[10,60], [90, 60], [10, 110], [90, 110]])
|
||||||
# metrics matrix
|
# metrics matrix
|
||||||
metricsSize = [1920,1080]
|
metricsSize = [1920,1080]
|
||||||
metricsSize = [1280,800]
|
metricsSize = [1280,800]
|
||||||
|
metricsSize = [960,600]
|
||||||
dataframe = pd.DataFrame(columns=['x','y'])
|
dataframe = pd.DataFrame(columns=['x','y'])
|
||||||
|
|
||||||
|
renderSize = [1280,800]
|
||||||
|
|
||||||
metrics = None
|
metrics = None
|
||||||
if lastMetricsFilename and os.path.isfile(lastMetricsFilename):
|
if lastMetricsFilename and os.path.isfile(lastMetricsFilename):
|
||||||
try:
|
try:
|
||||||
|
@ -250,13 +253,16 @@ if not args.hide_graph:
|
||||||
canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
|
canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
|
||||||
|
|
||||||
imageWindowRoot = Tk.Toplevel()
|
imageWindowRoot = Tk.Toplevel()
|
||||||
imageWindowSize = tuple(metricsSize)
|
imageWindowSize = tuple(renderSize)
|
||||||
imageWindowRoot.geometry('%dx%d+%d+%d' % (imageWindowSize[0],imageWindowSize[1],0,0))
|
imageWindowRoot.geometry('%dx%d+%d+%d' % (imageWindowSize[0],imageWindowSize[1],0,0))
|
||||||
imageWindowRoot.attributes("-fullscreen", True)
|
imageWindowRoot.attributes("-fullscreen", True)
|
||||||
# imageCanvas is where the heatmap image is drawn
|
# imageCanvas is where the heatmap image is drawn
|
||||||
imageCanvas = Tk.Canvas(imageWindowRoot,width=1280,height=800)
|
imageCanvas = Tk.Canvas(imageWindowRoot,width=renderSize[0],height=renderSize[1])
|
||||||
imageCanvas.pack()
|
imageCanvas.pack()
|
||||||
|
|
||||||
|
cv2.namedWindow("test", cv2.WND_PROP_FULLSCREEN)
|
||||||
|
cv2.setWindowProperty("test", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
|
||||||
|
|
||||||
|
|
||||||
if args.output_dir:
|
if args.output_dir:
|
||||||
startTime = time.time()
|
startTime = time.time()
|
||||||
|
@ -360,7 +366,7 @@ while True:
|
||||||
# rx = np.arctan2(rotMatrix[1,2]/np.cos(ry), rotMatrix[2,2]/np.cos(ry))
|
# rx = np.arctan2(rotMatrix[1,2]/np.cos(ry), rotMatrix[2,2]/np.cos(ry))
|
||||||
# rz = np.arctan2(rotMatrix[0,1]/np.cos(ry), rotMatrix[0,0]/np.cos(ry))
|
# rz = np.arctan2(rotMatrix[0,1]/np.cos(ry), rotMatrix[0,0]/np.cos(ry))
|
||||||
# logger.info("rotation ml {} {} {}".format(rx, ry, rz) )# seems better?
|
# logger.info("rotation ml {} {} {}".format(rx, ry, rz) )# seems better?
|
||||||
viewDirectionVector = np.dot(np.array([0.0, 0.0, 1000.0]), rotMatrix)
|
viewDirectionVector = np.dot(np.array([0.0, 0.0, 1.0]), rotMatrix)
|
||||||
|
|
||||||
if not args.hide_preview:
|
if not args.hide_preview:
|
||||||
# draw little floorplan for x: 10 -> 50 maps to z: 0 -> 10000, x: -2000 -> 2000
|
# draw little floorplan for x: 10 -> 50 maps to z: 0 -> 10000, x: -2000 -> 2000
|
||||||
|
@ -392,13 +398,15 @@ while True:
|
||||||
# => a = -t3 / r3
|
# => a = -t3 / r3
|
||||||
# substitute found a in x,y
|
# substitute found a in x,y
|
||||||
|
|
||||||
a = - translation_vector[2] / rotation_vector[2]
|
# seems to be wrong?
|
||||||
|
a = - translation_vector[2]# / rotation_vector[2]
|
||||||
x = translation_vector[0] + rotation_vector[0] * a
|
x = translation_vector[0] + rotation_vector[0] * a
|
||||||
y = translation_vector[1] + rotation_vector[1] * a
|
y = translation_vector[1] + rotation_vector[1] * a
|
||||||
|
logger.warn("First {} {},{}".format(a,x,y))
|
||||||
# a = - translation_vector[2] / viewDirectionVector[2]
|
a = - translation_vector[2]# / viewDirectionVector[2]
|
||||||
# x = translation_vector[0] + viewDirectionVector[0] * a
|
x = translation_vector[0] + viewDirectionVector[0] * a
|
||||||
# y = translation_vector[1] + viewDirectionVector[1] * a
|
y = translation_vector[1] + viewDirectionVector[1] * a
|
||||||
|
logger.warn("Second {} {},{}".format(a,x,y))
|
||||||
point = np.array([x,y])
|
point = np.array([x,y])
|
||||||
|
|
||||||
currentPoint = point
|
currentPoint = point
|
||||||
|
@ -456,11 +464,12 @@ while True:
|
||||||
dataframe = dataframe.append({'x':targetInt[0],'y':targetInt[1]}, ignore_index=True)
|
dataframe = dataframe.append({'x':targetInt[0],'y':targetInt[1]}, ignore_index=True)
|
||||||
logger.debug("Put metric {},{} in metrix of {},{}".format(targetInt[1],targetInt[0], metricsSize[1], metricsSize[0]))
|
logger.debug("Put metric {},{} in metrix of {},{}".format(targetInt[1],targetInt[0], metricsSize[1], metricsSize[0]))
|
||||||
newMetrics[targetInt[1],targetInt[0]] += 1
|
newMetrics[targetInt[1],targetInt[0]] += 1
|
||||||
|
# TODO: put in an image of a blurred spot & remove blur action
|
||||||
|
|
||||||
# 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()
|
||||||
metrics = metrics + gaussian_filter(newMetrics, sigma = 8)
|
metrics = metrics + gaussian_filter(newMetrics, sigma = 13)
|
||||||
tm4 = time.time()
|
tm4 = time.time()
|
||||||
logger.debug("Updated matrix with blur in %f", tm4 - tm3 + tm2 - tm1)
|
logger.debug("Updated matrix with blur in %f", tm4 - tm3 + tm2 - tm1)
|
||||||
|
|
||||||
|
@ -477,28 +486,34 @@ while True:
|
||||||
|
|
||||||
# update the heatmap output
|
# update the heatmap output
|
||||||
tm21 = time.time()
|
tm21 = time.time()
|
||||||
normalisedMetrics = metrics / (np.max(metrics))
|
# smooth impact of first hits by having at least 0.05
|
||||||
|
normalisedMetrics = metrics / (max(.02, np.max(metrics)))
|
||||||
# convert to colormap, thanks to: https://stackoverflow.com/a/10967471
|
# convert to colormap, thanks to: https://stackoverflow.com/a/10967471
|
||||||
normalisedMetricsColored = np.uint8(cm.plasma(normalisedMetrics)*255)
|
normalisedMetricsColored = np.uint8(cm.nipy_spectral(normalisedMetrics)*255)
|
||||||
|
normalisedMetricsColoredBGR = cv2.cvtColor(normalisedMetricsColored, cv2.COLOR_RGB2BGR)
|
||||||
|
|
||||||
tm22 = time.time()
|
tm22 = time.time()
|
||||||
logger.debug("Max normalised metrics: %f", np.max(normalisedMetrics))
|
logger.debug("Max normalised metrics: %f", np.max(normalisedMetrics))
|
||||||
# logger.info(normalisedMetrics)
|
# logger.info(normalisedMetrics)
|
||||||
tm23 = time.time()
|
tm23 = time.time()
|
||||||
image = Image.fromarray(normalisedMetricsColored)
|
|
||||||
wpercent = (imageWindowSize[0] / float(image.size[0]))
|
|
||||||
hsize = int((float(image.size[1]) * float(wpercent)))
|
|
||||||
image = image.resize((imageWindowSize[0], hsize))
|
|
||||||
|
|
||||||
if args.queue_length:
|
cv2.imshow("test",normalisedMetricsColoredBGR)
|
||||||
imageQueue.append(image)
|
# image = Image.fromarray(normalisedMetricsColored)
|
||||||
if len(imageQueue) > args.queue_length:
|
# wpercent = (imageWindowSize[0] / float(image.size[0]))
|
||||||
logger.warn("Use image from queue :-)")
|
# hsize = int((float(image.size[1]) * float(wpercent)))
|
||||||
image = imageQueue.pop(0)
|
# renderImage = image.resize((renderSize[0], renderSize[1]))
|
||||||
|
# print(renderImage.size, "lala")
|
||||||
|
|
||||||
tkpi = ImageTk.PhotoImage(image)
|
# if args.queue_length:
|
||||||
imageCanvas.delete("IMG")
|
# imageQueue.append(image)
|
||||||
imagesprite = imageCanvas.create_image(metricsSize[0]/2, metricsSize[1]/2,image=tkpi, tags="IMG")
|
# if len(imageQueue) > args.queue_length:
|
||||||
imageWindowRoot.update()
|
# logger.warn("Use image from queue :-)")
|
||||||
|
# image = imageQueue.pop(0)
|
||||||
|
|
||||||
|
# tkpi = ImageTk.PhotoImage(renderImage)
|
||||||
|
# imageCanvas.delete("IMG")
|
||||||
|
# imagesprite = imageCanvas.create_image(renderSize[0]/2, renderSize[1]/2,image=tkpi, tags="IMG")
|
||||||
|
# imageWindowRoot.update()
|
||||||
tm24 = time.time()
|
tm24 = time.time()
|
||||||
logger.debug("PIL image generated in %fs", tm24 - tm23)
|
logger.debug("PIL image generated in %fs", tm24 - tm23)
|
||||||
logger.debug("Total matrix time is %fs", tm4 - tm3 + tm2 - tm1 + tm24 - tm21)
|
logger.debug("Total matrix time is %fs", tm4 - tm3 + tm2 - tm1 + tm24 - tm21)
|
||||||
|
@ -513,7 +528,6 @@ while True:
|
||||||
te5 = time.time()
|
te5 = time.time()
|
||||||
logger.debug("Drew graph & updated window in %fs", te5-te4)
|
logger.debug("Drew graph & updated window in %fs", te5-te4)
|
||||||
|
|
||||||
logger.warn("{}".format(image.size))
|
|
||||||
if args.output_dir:
|
if args.output_dir:
|
||||||
# save output to dir
|
# save output to dir
|
||||||
now = tm24 # time.time()
|
now = tm24 # time.time()
|
||||||
|
@ -524,7 +538,8 @@ while True:
|
||||||
datetime.datetime.now().replace(microsecond=0).isoformat()
|
datetime.datetime.now().replace(microsecond=0).isoformat()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
image.save(filename)
|
cv2.imwrite(filename, normalisedMetricsColoredBGR)
|
||||||
|
# image.save(filename)
|
||||||
|
|
||||||
with open(lastMetricsFilename, 'wb') as fp:
|
with open(lastMetricsFilename, 'wb') as fp:
|
||||||
pickle.dump( metrics, fp )
|
pickle.dump( metrics, fp )
|
||||||
|
|
Loading…
Reference in a new issue