aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThéo de la Hogue2023-08-08 08:14:27 +0200
committerThéo de la Hogue2023-08-08 08:14:27 +0200
commit3861fd896c3b2b3e0136c253dbd57086b53c9bb2 (patch)
tree45572487532550de870ecd914521a49adfdfe807
parentd3bac261370af747a0baea2d72bfa35f1621c012 (diff)
downloadargaze-3861fd896c3b2b3e0136c253dbd57086b53c9bb2.zip
argaze-3861fd896c3b2b3e0136c253dbd57086b53c9bb2.tar.gz
argaze-3861fd896c3b2b3e0136c253dbd57086b53c9bb2.tar.bz2
argaze-3861fd896c3b2b3e0136c253dbd57086b53c9bb2.tar.xz
Adding new ArEnvironment map method to project camera frame backgrund into aoi frame background.
-rw-r--r--src/argaze/ArFeatures.py40
1 files changed, 39 insertions, 1 deletions
diff --git a/src/argaze/ArFeatures.py b/src/argaze/ArFeatures.py
index 03082e6..b884020 100644
--- a/src/argaze/ArFeatures.py
+++ b/src/argaze/ArFeatures.py
@@ -1274,7 +1274,10 @@ class ArEnvironment():
return detection_time, exceptions
def look(self, timestamp: int|float, gaze_position: GazeFeatures.GazePosition):
- """Project timestamped gaze position into each frame."""
+ """Project timestamped gaze position into each frame.
+
+ .. warning:: detect_and_project method needs to be called first.
+ """
# Can't use camera frame when it is locked
if self.__camera_frame_lock.locked():
@@ -1317,6 +1320,41 @@ class ArEnvironment():
# Unlock camera frame exploitation
self.__camera_frame_lock.release()
+ def map(self):
+ """Project camera frame background into aoi frames background.
+
+ .. warning:: detect_and_project method needs to be called first.
+ """
+
+ # Can't use camera frame when it is locked
+ if self.__camera_frame_lock.locked():
+ return
+
+ # Lock camera frame exploitation
+ self.__camera_frame_lock.acquire()
+
+ # Project image if possible
+ for aoi_frame in self.aoi_frames:
+
+ # Is aoi frame projected into camera frame ?
+ try:
+
+ aoi_2d = self.camera_frame.aoi_2d_scene[aoi_frame.name]
+
+ # Apply perspective transform algorithm to fill aoi frame background
+ width, height = aoi_frame.size
+ destination = numpy.float32([[0, height],[width, height],[width, 0],[0, 0]])
+ mapping = cv2.getPerspectiveTransform(aoi_2d.astype(numpy.float32), destination)
+ aoi_frame.background = cv2.warpPerspective(self.camera_frame.background, mapping, (width, height))
+
+ # Ignore missing aoi frame projection
+ except KeyError:
+
+ pass
+
+ # Unlock camera frame exploitation
+ self.__camera_frame_lock.release()
+
def to_json(self, json_filepath):
"""Save environment to .json file."""