aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/argaze.test/ArGazeProject.py31
-rw-r--r--src/argaze.test/utils/project.json36
-rw-r--r--src/argaze/ArGazeProject.py35
-rw-r--r--src/argaze/__init__.py2
4 files changed, 103 insertions, 1 deletions
diff --git a/src/argaze.test/ArGazeProject.py b/src/argaze.test/ArGazeProject.py
new file mode 100644
index 0000000..f37e1f5
--- /dev/null
+++ b/src/argaze.test/ArGazeProject.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python
+
+import unittest
+import os
+
+from argaze import ArGazeProject
+
+
+class TestArGazeProjectClass(unittest.TestCase):
+ """Test ArGazeProject class."""
+
+ def test_from_json(self):
+ """Test ArGazeProject creation from json file."""
+
+ # Edit project file path
+ current_directory = os.path.dirname(os.path.abspath(__file__))
+ json_filepath = os.path.join(current_directory, 'utils/project.json')
+
+ # Load project
+ argaze_project = ArGazeProject.ArGazeProject.from_json(json_filepath)
+
+ # Check project meta data
+ self.assertEqual(argaze_project.name, "TestProject")
+
+ # Check ArUco camera
+ print(argaze_project.aruco_camera)
+ self.assertEqual(argaze_project.aruco_camera.rms, 0.)
+
+if __name__ == '__main__':
+
+ unittest.main() \ No newline at end of file
diff --git a/src/argaze.test/utils/project.json b/src/argaze.test/utils/project.json
new file mode 100644
index 0000000..96c644b
--- /dev/null
+++ b/src/argaze.test/utils/project.json
@@ -0,0 +1,36 @@
+{
+ "name": "TestProject",
+ "aruco_camera": {
+ "rms": 0.0,
+ "dimensions": [
+ 1920,
+ 1080
+ ],
+ "K": [
+ [
+ 1.0,
+ 0.0,
+ 1.0
+ ],
+ [
+ 0.0,
+ 1.0,
+ 1.0
+ ],
+ [
+ 0.0,
+ 0.0,
+ 1.0
+ ]
+ ],
+ "D": [
+ [
+ 0.0,
+ 0.0,
+ 0.0,
+ 0.0,
+ 0.0
+ ]
+ ]
+ }
+} \ No newline at end of file
diff --git a/src/argaze/ArGazeProject.py b/src/argaze/ArGazeProject.py
new file mode 100644
index 0000000..757d65c
--- /dev/null
+++ b/src/argaze/ArGazeProject.py
@@ -0,0 +1,35 @@
+#!/usr/bin/env python
+
+from typing import TypeVar
+from dataclasses import dataclass, field
+import json
+
+from argaze.ArUcoMarkers import *
+from argaze.AreaOfInterest import *
+
+ArGazeProjectType = TypeVar('ArGazeProject', bound="ArGazeProject")
+# Type definition for type annotation convenience
+
+@dataclass
+class ArGazeProject():
+ """Define an Augmented Reality environnement thanks to ArUco markers and project gaze on it to know where is looking at."""
+
+ name: str
+ """Project name."""
+
+ aruco_camera: ArUcoCamera.ArUcoCamera = field(init=False, default_factory=ArUcoCamera.ArUcoCamera)
+ """ArUco camera ..."""
+
+ def __init__(self, **kwargs):
+
+ self.aruco_camera = ArUcoCamera.ArUcoCamera(**kwargs.pop('aruco_camera'))
+
+ self.__dict__.update(kwargs)
+
+ @classmethod
+ def from_json(self, json_filepath) -> ArGazeProjectType:
+ """Load ArGaze project from .json file."""
+
+ with open(json_filepath) as configuration_file:
+
+ return ArGazeProject(**json.load(configuration_file)) \ No newline at end of file
diff --git a/src/argaze/__init__.py b/src/argaze/__init__.py
index 4945206..baa46f7 100644
--- a/src/argaze/__init__.py
+++ b/src/argaze/__init__.py
@@ -2,4 +2,4 @@
.. include:: ../../README.md
"""
__docformat__ = "restructuredtext"
-__all__ = ['utils','ArUcoMarkers','AreaOfInterest','GazeFeatures','DataStructures','GazeAnalysis','TobiiGlassesPro2'] \ No newline at end of file
+__all__ = ['utils','ArUcoMarkers','AreaOfInterest','GazeFeatures','DataStructures','GazeAnalysis','ArGazeProject','TobiiGlassesPro2'] \ No newline at end of file