Changes in output

This commit is contained in:
Ruben van de Ven 2019-02-05 23:48:08 +01:00
parent d6e54cf59a
commit 02627cf897
1 changed files with 41 additions and 26 deletions

View File

@ -101,8 +101,11 @@ screenDrawCorners = np.array([[10,60], [90, 60], [10, 110], [90, 110]])
# metrics matrix
metricsSize = [1920,1080]
metricsSize = [1280,800]
metricsSize = [960,600]
dataframe = pd.DataFrame(columns=['x','y'])
renderSize = [1280,800]
metrics = None
if lastMetricsFilename and os.path.isfile(lastMetricsFilename):
try:
@ -250,13 +253,16 @@ if not args.hide_graph:
canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
imageWindowRoot = Tk.Toplevel()
imageWindowSize = tuple(metricsSize)
imageWindowSize = tuple(renderSize)
imageWindowRoot.geometry('%dx%d+%d+%d' % (imageWindowSize[0],imageWindowSize[1],0,0))
imageWindowRoot.attributes("-fullscreen", True)
# 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()
cv2.namedWindow("test", cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty("test", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
if args.output_dir:
startTime = time.time()
@ -360,7 +366,7 @@ while True:
# 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))
# 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:
# draw little floorplan for x: 10 -> 50 maps to z: 0 -> 10000, x: -2000 -> 2000
@ -392,13 +398,15 @@ while True:
# => a = -t3 / r3
# 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
y = translation_vector[1] + rotation_vector[1] * a
# a = - translation_vector[2] / viewDirectionVector[2]
# x = translation_vector[0] + viewDirectionVector[0] * a
# y = translation_vector[1] + viewDirectionVector[1] * a
logger.warn("First {} {},{}".format(a,x,y))
a = - translation_vector[2]# / viewDirectionVector[2]
x = translation_vector[0] + viewDirectionVector[0] * a
y = translation_vector[1] + viewDirectionVector[1] * a
logger.warn("Second {} {},{}".format(a,x,y))
point = np.array([x,y])
currentPoint = point
@ -456,11 +464,12 @@ while 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]))
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
# and add to all metrics collected
tm3 = time.time()
metrics = metrics + gaussian_filter(newMetrics, sigma = 8)
metrics = metrics + gaussian_filter(newMetrics, sigma = 13)
tm4 = time.time()
logger.debug("Updated matrix with blur in %f", tm4 - tm3 + tm2 - tm1)
@ -477,28 +486,34 @@ while True:
# update the heatmap output
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
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()
logger.debug("Max normalised metrics: %f", np.max(normalisedMetrics))
# logger.info(normalisedMetrics)
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:
imageQueue.append(image)
if len(imageQueue) > args.queue_length:
logger.warn("Use image from queue :-)")
image = imageQueue.pop(0)
cv2.imshow("test",normalisedMetricsColoredBGR)
# image = Image.fromarray(normalisedMetricsColored)
# wpercent = (imageWindowSize[0] / float(image.size[0]))
# hsize = int((float(image.size[1]) * float(wpercent)))
# renderImage = image.resize((renderSize[0], renderSize[1]))
# print(renderImage.size, "lala")
tkpi = ImageTk.PhotoImage(image)
imageCanvas.delete("IMG")
imagesprite = imageCanvas.create_image(metricsSize[0]/2, metricsSize[1]/2,image=tkpi, tags="IMG")
imageWindowRoot.update()
# if args.queue_length:
# imageQueue.append(image)
# if len(imageQueue) > args.queue_length:
# 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()
logger.debug("PIL image generated in %fs", tm24 - tm23)
logger.debug("Total matrix time is %fs", tm4 - tm3 + tm2 - tm1 + tm24 - tm21)
@ -513,7 +528,6 @@ while True:
te5 = time.time()
logger.debug("Drew graph & updated window in %fs", te5-te4)
logger.warn("{}".format(image.size))
if args.output_dir:
# save output to dir
now = tm24 # time.time()
@ -524,7 +538,8 @@ while True:
datetime.datetime.now().replace(microsecond=0).isoformat()
)
)
image.save(filename)
cv2.imwrite(filename, normalisedMetricsColoredBGR)
# image.save(filename)
with open(lastMetricsFilename, 'wb') as fp:
pickle.dump( metrics, fp )