def update_location(self, frame_idx, marker_cache, camera_model):
        if not self.defined:
            self._build_definition_from_cache(camera_model, frame_idx,
                                              marker_cache)

        self._fetch_from_location_cache_filler()
        try:
            location = self.location_cache[frame_idx]
        except (TypeError, AttributeError):
            # If any event invalidates the location_cache, it will be set to None.
            location = None
            self._recalculate_location_cache(frame_idx, marker_cache,
                                             camera_model)

        # If location is None the cache was not filled at the current position yet.
        if location is None:
            if not marker_cache[frame_idx] is None:
                logging.debug("On demand surface cache update!")
                self.update_location_cache(frame_idx, marker_cache,
                                           camera_model)
                self.update_location(frame_idx, marker_cache, camera_model)
                return
            else:
                logging.debug("Markers not computed yet!")
                location = Surface_Location(detected=False)

        self.detected = location.detected
        self.dist_img_to_surf_trans = location.dist_img_to_surf_trans
        self.surf_to_dist_img_trans = location.surf_to_dist_img_trans
        self.img_to_surf_trans = location.img_to_surf_trans
        self.surf_to_img_trans = location.surf_to_img_trans
        self.num_detected_markers = location.num_detected_markers
    def _load_from_dict(self, init_dict):
        super()._load_from_dict(init_dict)
        try:
            cache = init_dict["cache"]
            for cache_idx in range(len(cache)):
                location = cache[cache_idx]
                cache[
                    cache_idx] = Surface_Location.load_from_serializable_copy(
                        location)

            self.location_cache = Cache(cache)
        except (KeyError, TypeError):
            self.location_cache = None

        try:
            added_in_player = init_dict["added_in_player"]
        except KeyError:
            # If surface was created in Capture, we just accept it as is
            self.observations_frame_idxs = []
            self.start_idx = 0
            self.build_up_status = 1.0
        else:
            self.observations_frame_idxs = added_in_player[
                "observations_frame_idxs"]
            self.start_idx = added_in_player["start_idx"]
示例#3
0
    def update_location_cache(self, frame_idx, marker_cache, camera_model):
        """ Update a single entry in the location cache."""

        try:
            if not marker_cache[frame_idx]:
                location = Surface_Location(detected=False)
            else:
                markers = marker_cache[frame_idx]
                markers = {m.id: m for m in markers}
                location = Surface.locate(
                    markers,
                    camera_model,
                    self.registered_markers_undist,
                    self.registered_markers_dist,
                )
            self.location_cache.update(frame_idx, location, force=True)
        except (TypeError, AttributeError):
            self._recalculate_location_cache(frame_idx, marker_cache, camera_model)
示例#4
0
    def _load_from_dict(self, init_dict):
        super()._load_from_dict(init_dict)
        try:
            cache = init_dict["cache"]
            for cache_idx in range(len(cache)):
                location = cache[cache_idx]
                cache[cache_idx] = Surface_Location.load_from_serializable_copy(
                    location
                )

            self.location_cache = Cache(cache)
        except (KeyError, TypeError):
            self.location_cache = None

        try:
            added_in_player = init_dict["added_in_player"]
        except KeyError:
            # If surface was created in Capture, we just accept it as is
            self.observations_frame_idxs = []
            self.start_idx = 0
            self.build_up_status = 1.0
        else:
            self.observations_frame_idxs = added_in_player["observations_frame_idxs"]
            self.start_idx = added_in_player["start_idx"]