Exemple #1
0
    def test_keypoints(self):
        p = self.setup_i3()
        kp1 = KeyPoint(Point2(3,6))
        kp2 = KeyPoint(Point2(5,5))
        p.imagery.add_keypoint(kp1)
        p.imagery.add_keypoint(kp2)

        align = KeyPointAlignment()
        p.imagery.imagelayers[0].set_alignment(align)

        align.set_keypoint_position(kp1, Point2(-7,13))
        align.set_keypoint_position(kp2, Point2(4, 5))

        p_new = self.__saverestore(p)

        # Verify Keypoints saved/restored
        self.assertEqual(len(p_new.imagery.keypoints), len(p.imagery.keypoints))
        for kp_old, kp_new in zip(p.imagery.keypoints, p_new.imagery.keypoints):
            self.check_obj(p_new, kp_new, kp_old)

            self.cmpMat(kp_new.world_position, kp_old.world_position)

        # Verify object align makes it through
        il_0_new = p_new.imagery.imagelayers[0]
        self.assertIsInstance(il_0_new.alignment, KeyPointAlignment)
        al = il_0_new.alignment

        new_kpl = sorted(al.keypoint_positions, key=lambda x: x.key_point.world_position.x)
        old_kpl = sorted(align.keypoint_positions, key=lambda x: x.key_point.world_position.x)

        self.cmpMat(new_kpl[0].image_pos, old_kpl[0].image_pos)
        self.cmpMat(new_kpl[1].image_pos, old_kpl[1].image_pos)
Exemple #2
0
    def save(self, project: 'Project') -> None:
        al = KeyPointAlignment()

        # Remove all keypoints that were deleted
        still_exist_pkp = set(i._orig_kp for i in self.keypoints
                              if hasattr(i, "_orig_kp"))
        for pkp in list(project.imagery.keypoints):
            if not pkp in still_exist_pkp:
                project.imagery.del_keypoint(pkp)

        # Now for all remaining keypoints, recreate
        for kp in self.keypoints:
            # Create or update the world kp
            if kp._orig_kp is None:
                pkp = KeyPoint(project, kp.world)
                kp._orig_kp = pkp
                project.imagery.add_keypoint(pkp)
            else:
                pkp = kp._orig_kp
                pkp.world_position = kp.world

        for kp in self.keypoints:
            if kp.use:
                if kp._orig_kp is not None:
                    al.set_keypoint_position(kp._orig_kp, kp.layer)

        # Now, save the changes to the layer
        self.__image.set_alignment(al)
        self.__image.transform_matrix = self.image_matrix
Exemple #3
0
    def save(self, project):
        al = KeyPointAlignment()

        # Remove all keypoints that were deleted
        still_exist_pkp = set(i._orig_kp for i in self.keypoints if hasattr(i, "_orig_kp"))
        for pkp in list(project.imagery.keypoints):
            if not pkp in still_exist_pkp:
                project.imagery.del_keypoint(pkp)

        # Now for all remaining keypoints, recreate
        for kp in self.keypoints:
            # Create or update the world kp
            if not hasattr(kp, "_orig_kp"):
                pkp = KeyPoint(kp.world)
                kp._orig_kp = pkp
                project.imagery.add_keypoint(pkp)
            else:
                pkp = kp._orig_kp
                pkp.world_position = kp.world

        for kp in self.keypoints:
            if kp.use:
                al.set_keypoint_position(kp._orig_kp, kp.layer)

        # Now, save the changes to the layer
        self.__image.set_alignment(al)
        self.__image.transform_matrix = self.image_matrix
Exemple #4
0
    def deserialize(self, msg):
        # Keypoints may be used by the imagelayers during deserialize
        # Deserialize first to avoid a finalizer
        for i in msg.keypoints:
            self.__keypoints.append(KeyPoint.deserialize(self.__project, i))

        for i in msg.imagelayers:
            self.__imagelayers.append(ImageLayer.deserialize(self.__project, i))
Exemple #5
0
    def deserialize(self, msg: ser.Imagery) -> None:
        # Keypoints may be used by the imagelayers during deserialize
        # Deserialize first to avoid a finalizer
        for i in msg.keypoints:
            self.__keypoints.append(KeyPoint.deserialize(self.__project, i))

        for i in msg.imagelayers:
            self.__imagelayers.append(ImageLayer.deserialize(self.__project, i))
Exemple #6
0
    def del_keypoint(self, kp: KeyPoint) -> None:
        """
        Remove a keypoint from the project
        :param kp: Keypoint to remove from the project
        :type kp: KeyPoint
        :return:
        """

        assert kp._project is self.__project
        # Verify that no layers use the keypoint
        assert len(kp.layer_positions) == 0

        kp._project = None

        self.__keypoints.remove(kp)
Exemple #7
0
 def add_keypoint(self, kp: KeyPoint) -> None:
     assert kp._project is None or kp._project is self.__project
     kp._project = self.__project
     self.__keypoints.append(kp)