From 3861fd896c3b2b3e0136c253dbd57086b53c9bb2 Mon Sep 17 00:00:00 2001 From: Théo de la Hogue Date: Tue, 8 Aug 2023 08:14:27 +0200 Subject: Adding new ArEnvironment map method to project camera frame backgrund into aoi frame background. --- src/argaze/ArFeatures.py | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) 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.""" -- cgit v1.1