def test_keyPointCreation(self): p = self.p il1 = IL.ImageLayer(name="foo", data=bytes()) il2 = IL.ImageLayer(name="bar", data=bytes()) p.imagery.add_imagelayer(il1) p.imagery.add_imagelayer(il2) kp1 = IL.KeyPoint(Point2(5,5)) kp2 = IL.KeyPoint(Point2(10,20)) p.imagery.add_keypoint(kp1) p.imagery.add_keypoint(kp2) # Verify that keypoint indicies are working as expected self.assertEqual(kp1.index, 0) self.assertEqual(kp2.index, 1) # al = KeyPointAlignment() il1.set_alignment(al) al.set_keypoint_position(kp1, Point2(0,2)) kp_set = il1.alignment.keypoint_positions kpp0 = list(kp_set)[0] self.assertEqual(kpp0.key_point, kp1) eps = numpy.absolute(kpp0.image_pos - Point2(0,2)).max() self.assertLess(eps, 0.0000001) al.remove_keypoint(kp1) self.assertEqual(len(kp_set), 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
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
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)
def test_keyPointCreation(self): p = self.p il1 = IL.ImageLayer(name="foo", data=bytes()) il2 = IL.ImageLayer(name="bar", data=bytes()) p.imagery.add_imagelayer(il1) p.imagery.add_imagelayer(il2) kp1 = IL.KeyPoint(Point2(5, 5)) kp2 = IL.KeyPoint(Point2(10, 20)) p.imagery.add_keypoint(kp1) p.imagery.add_keypoint(kp2) # Verify that keypoint indicies are working as expected self.assertEqual(kp1.index, 0) self.assertEqual(kp2.index, 1) # al = KeyPointAlignment() il1.set_alignment(al) al.set_keypoint_position(kp1, Point2(0, 2)) kp_set = il1.alignment.keypoint_positions kpp0 = list(kp_set)[0] self.assertEqual(kpp0.key_point, kp1) eps = numpy.absolute(kpp0.image_pos - Point2(0, 2)).max() self.assertLess(eps, 0.0000001) al.remove_keypoint(kp1) self.assertEqual(len(kp_set), 0)
def test_keyPointLayerPositions(self): p = self.p il1 = IL.ImageLayer(name="foo", data=bytes()) il2 = IL.ImageLayer(name="bar", data=bytes()) p.imagery.add_imagelayer(il1) p.imagery.add_imagelayer(il2) kp1 = IL.KeyPoint(Point2(5, 5)) kp2 = IL.KeyPoint(Point2(10, 20)) p.imagery.add_keypoint(kp1) p.imagery.add_keypoint(kp2) al = KeyPointAlignment() il2.set_alignment(al) al.set_keypoint_position(kp1, Point2(5, 4)) ll = kp1.layer_positions self.assertEqual(len(ll), 1) self.assertIs(ll[0][0], il2) self.assertEqual(ll[0][1].x, 5) self.assertEqual(ll[0][1].y, 4)
def test_keyPointLayerPositions(self): p = self.p il1 = IL.ImageLayer(name="foo", data=bytes()) il2 = IL.ImageLayer(name="bar", data=bytes()) p.imagery.add_imagelayer(il1) p.imagery.add_imagelayer(il2) kp1 = IL.KeyPoint(Point2(5,5)) kp2 = IL.KeyPoint(Point2(10,20)) p.imagery.add_keypoint(kp1) p.imagery.add_keypoint(kp2) al = KeyPointAlignment() il2.set_alignment(al) al.set_keypoint_position(kp1, Point2(5,4)) ll = kp1.layer_positions self.assertEqual(len(ll), 1) self.assertIs(ll[0][0], il2) self.assertEqual(ll[0][1].x, 5) self.assertEqual(ll[0][1].y, 4)