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