aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThéo de la Hogue2023-05-22 12:32:52 +0200
committerThéo de la Hogue2023-05-22 12:32:52 +0200
commit847685f1a611f254aa1f20228bee6d72f3da0245 (patch)
tree1934b73f9c4c18f272743620f0c5e13f0df9dc46
parent846b5bf301b79e6725c32114532eaf50e1379a81 (diff)
downloadargaze-847685f1a611f254aa1f20228bee6d72f3da0245.zip
argaze-847685f1a611f254aa1f20228bee6d72f3da0245.tar.gz
argaze-847685f1a611f254aa1f20228bee6d72f3da0245.tar.bz2
argaze-847685f1a611f254aa1f20228bee6d72f3da0245.tar.xz
Buffering gaze spread to get real time heatmap effect.
-rw-r--r--src/argaze/utils/demo_gaze_features_run.py37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/argaze/utils/demo_gaze_features_run.py b/src/argaze/utils/demo_gaze_features_run.py
index 6e7e01e..67c7a52 100644
--- a/src/argaze/utils/demo_gaze_features_run.py
+++ b/src/argaze/utils/demo_gaze_features_run.py
@@ -11,6 +11,7 @@ import argparse
import os
import time
import threading
+import queue
from argaze import ArFeatures, GazeFeatures
from argaze.AreaOfInterest import AOIFeatures
@@ -59,9 +60,13 @@ def main():
screen_frame = AOIFeatures.AOIFrame(aoi_scene_projection['Screen'], window_size)
gaze_spread_sum = numpy.zeros((aoi_scene_image.shape[0], aoi_scene_image.shape[1]))
+ gaze_spread_buffer = []
+ gaze_spread_buffer_size = 10
heatmap_matrix = numpy.zeros(aoi_scene_image.shape, dtype=numpy.uint8)
enable_heatmap = False
+ clear_sum_and_buffer = False
+ enable_heatmap_buffer = False
gaze_movement_identifier = {
'I-DT': DispersionThresholdIdentification.GazeMovementIdentifier(args.deviation_max_threshold, args.duration_min_threshold),
@@ -95,7 +100,9 @@ def main():
nonlocal gaze_position
nonlocal gaze_spread_sum
+ nonlocal gaze_spread_buffer
nonlocal heatmap_matrix
+ nonlocal clear_sum_and_buffer
nonlocal tpm_analysis
nonlocal raw_cK_analysis
nonlocal aoi_cK_analysis
@@ -116,7 +123,23 @@ def main():
# Edit heatmap
if enable_heatmap:
- gaze_spread_sum += screen_frame.point_spread(gaze_position.value, sigma=0.05)
+ gaze_spread = screen_frame.point_spread(gaze_position.value, sigma=0.05)
+
+ # Clear sum and buffer once
+ if clear_sum_and_buffer:
+ gaze_spread_sum = numpy.zeros((aoi_scene_image.shape[0], aoi_scene_image.shape[1]))
+ gaze_spread_buffer = []
+ clear_sum_and_buffer = False
+
+ # Sum and and fill buffer
+ gaze_spread_sum += gaze_spread
+ gaze_spread_buffer.append(gaze_spread)
+
+ # remove oldest gaze_spread buffer frame
+ if enable_heatmap_buffer and len(gaze_spread_buffer) > gaze_spread_buffer_size:
+
+ gaze_spread_sum -= gaze_spread_buffer.pop(0)
+
heatmap_gray = (255 * gaze_spread_sum / numpy.max(gaze_spread_sum)).astype(numpy.uint8)
heatmap_matrix = cv2.applyColorMap(heatmap_gray, cv2.COLORMAP_JET)
@@ -200,7 +223,9 @@ def main():
# Write heatmap help
on_off = 'on' if enable_heatmap else 'off'
enable_disable = 'disable' if enable_heatmap else 'enable'
- cv2.putText(aoi_matrix, f'Heatmap: {on_off} (Press \'h\' key to {enable_disable})', (20, 40), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 1, cv2.LINE_AA)
+ buffer_on_off = 'on' if enable_heatmap_buffer else 'off'
+ buffer_enable_disable = 'disable' if enable_heatmap_buffer else 'enable'
+ cv2.putText(aoi_matrix, f'Heatmap: {on_off} (Press \'h\' key to {enable_disable}), Buffer: {buffer_on_off} (Press \'b\' key to {buffer_enable_disable})', (20, 40), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 1, cv2.LINE_AA)
# Draw gaze spread heatmap
if enable_heatmap:
@@ -326,6 +351,14 @@ def main():
enable_heatmap = not enable_heatmap
+ # Enable heatmap buffer with 'b' key
+ if key_pressed == 98:
+
+ enable_heatmap_buffer = not enable_heatmap_buffer
+
+ if enable_heatmap_buffer:
+ clear_sum_and_buffer = True
+
# Enable cK analysis with 'k' key
if key_pressed == 107: