aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThéo de la Hogue2023-07-11 11:03:35 +0200
committerThéo de la Hogue2023-07-11 11:03:35 +0200
commit5ebea7a08ea7fe9c7a1027fdff860b6990cdf6ca (patch)
treea183ed7164fc2602548493b626460ad3ecb878fa /src
parent77396cff852c637e5c6e52a46bd4d2c1d84a52f7 (diff)
downloadargaze-5ebea7a08ea7fe9c7a1027fdff860b6990cdf6ca.zip
argaze-5ebea7a08ea7fe9c7a1027fdff860b6990cdf6ca.tar.gz
argaze-5ebea7a08ea7fe9c7a1027fdff860b6990cdf6ca.tar.bz2
argaze-5ebea7a08ea7fe9c7a1027fdff860b6990cdf6ca.tar.xz
Loading aoi_2d_scene from json. Loading ArFrame from json.
Diffstat (limited to 'src')
-rw-r--r--src/argaze/ArFeatures.py44
1 files changed, 41 insertions, 3 deletions
diff --git a/src/argaze/ArFeatures.py b/src/argaze/ArFeatures.py
index 1569873..6ef8df3 100644
--- a/src/argaze/ArFeatures.py
+++ b/src/argaze/ArFeatures.py
@@ -76,8 +76,8 @@ class ArFrame():
name: str
size: tuple[int] = field(default=(1, 1))
+ aoi_2d_scene: AOI2DScene.AOI2DScene = field(default_factory=AOI2DScene.AOI2DScene)
background: numpy.array = field(default_factory=numpy.array)
- aoi_2d_scene: AOI2DScene.AOI2DScene = field(init=False, default_factory=AOI2DScene.AOI2DScene)
gaze_movement_identifier: GazeFeatures.GazeMovementIdentifier = field(default_factory=GazeFeatures.GazeMovementIdentifier)
scan_path: GazeFeatures.ScanPath = field(default_factory=GazeFeatures.ScanPath)
scan_path_analyzers: dict = field(default_factory=dict)
@@ -122,6 +122,26 @@ class ArFrame():
new_frame_size = (0, 0)
+ # Load aoi 2D scene
+ try:
+
+ new_aoi_2d_scene_value = frame_data.pop('aoi_2d_scene')
+
+ # str: relative path to .json file
+ if type(new_aoi_2d_scene_value) == str:
+
+ json_filepath = os.path.join(working_directory, new_aoi_2d_scene_value)
+ new_aoi_2d_scene = AOI2DScene.AOI2DScene.from_json(obj_filepath)
+
+ # dict:
+ else:
+
+ new_aoi_2d_scene = AOI2DScene.AOI2DScene(new_aoi_2d_scene_value)
+
+ except KeyError:
+
+ new_aoi_2d_scene = AOI2DScene.AOI2DScene()
+
# Load background image
try:
@@ -247,6 +267,7 @@ class ArFrame():
# Create frame
return ArFrame(new_frame_name, \
new_frame_size, \
+ new_aoi_2d_scene, \
new_frame_background, \
finished_gaze_movement_identifier, \
GazeFeatures.ScanPath() if len(new_scan_path_analyzers) > 0 else None, \
@@ -255,6 +276,23 @@ class ArFrame():
new_aoi_scan_path_analyzers, \
AOIFeatures.Heatmap(new_frame_size) if new_heatmap_value else None \
)
+
+ @classmethod
+ def from_json(self, json_filepath: str) -> ArEnvironmentType:
+ """
+ Load ArFrame from .json file.
+
+ Parameters:
+ json_filepath: path to json file
+ """
+
+ with open(json_filepath) as configuration_file:
+
+ frame_data = json.load(configuration_file)
+ working_directory = os.path.dirname(json_filepath)
+
+ return ArFrame.from_dict(frame_data, working_directory)
+
@property
def parent(self):
"""Get parent instance"""
@@ -433,7 +471,7 @@ class ArFrame():
# Return look data
return fixation, look_at, scan_step_analysis, aoi_scan_step_analysis, exception
- def draw(self, image:numpy.array):
+ def draw(self, image:numpy.array, aoi_color=(0, 0, 0)):
"""
Draw frame into image.
@@ -445,7 +483,7 @@ class ArFrame():
self.__look_lock.acquire()
# Draw aoi
- self.aoi_2d_scene.draw(image, color=(0, 0, 0))
+ self.aoi_2d_scene.draw(image, color=aoi_color)
# Draw current gaze position
self.__gaze_position.draw(image, color=(255, 255, 255))