Exemplo n.º 1
0
    def test_fitting_vector_dimension(self):
        with self.assertRaises(Exception):
            listA = [[0, 0], [1, 0], [0, 1]]
            listB = [[0, 0, 0], [1, 0, 0], [0, 1, 0]]
            psf.point_sets_fitting(listA, listB)

        with self.assertRaises(Exception):
            listA = [[0, 0, 0], [1, 0, 0], [0, 1, 0]]
            listB = [[0, 0], [1, 0], [0, 1]]
            psf.point_sets_fitting(listA, listB)
Exemplo n.º 2
0
    def test_fitting_translation(self):

        setA = np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0,
                                                           2]]).transpose()
        expectedTransformation = compose([10, 2, 5], np.eye(3, 3), np.ones(3))
        setB = expectedTransformation @ psf.to_homogeneous_repr(setA)

        expectedError = 0

        transformation, err = psf.point_sets_fitting(setA, setB[0:3, :])

        np.testing.assert_array_almost_equal(expectedTransformation,
                                             transformation,
                                             decimal=5)
        self.assertAlmostEqual(expectedError, err, delta=0.0001)
Exemplo n.º 3
0
    def test_fitting_identity(self):

        set_a = np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0,
                                                            2]]).transpose()
        set_b = np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0,
                                                            2]]).transpose()

        expected_error = 0
        expected_transformation = np.eye(4, 4)

        transformation, err = psf.point_sets_fitting(set_a, set_b)

        np.testing.assert_array_almost_equal(expected_transformation,
                                             transformation,
                                             decimal=5)
        self.assertAlmostEqual(expected_error, err, delta=0.0001)
Exemplo n.º 4
0
    def test_fitting_noisefree_10P(self):

        for k in range(1000):
            setA = np.random.rand(3, 10)
            trans = np.random.rand(1, 3)
            expTr = compose(
                trans[0, :],
                euler2mat(np.random.rand(), np.random.rand(),
                          np.random.rand()), np.ones(3))
            setB = expTr @ psf.to_homogeneous_repr(setA)

            expError = 0

            transformation, err = psf.point_sets_fitting(setA, setB[0:3, :])

            np.testing.assert_array_almost_equal(expTr,
                                                 transformation,
                                                 decimal=5)
            self.assertAlmostEqual(expError, err, delta=0.0001)
Exemplo n.º 5
0
 def test_fitting_too_few_points(self):
     with self.assertRaises(Exception):
         listA = [[0, 0, 0], [1, 0, 0]]
         listB = [[0, 0, 0], [1, 0, 0]]
         psf.point_sets_fitting(listA, listB)
Exemplo n.º 6
0
 def test_fitting_differen_set_lengths(self):
     with self.assertRaises(Exception):
         listA = [[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 2]]
         listB = [[0, 0, 0], [1, 0, 0], [0, 1, 0]]
         psf.point_sets_fitting(listA, listB)
Exemplo n.º 7
0
if __name__ == '__main__':

    obj_path_name = utility.return_obj_path(
        "C:/Users/user/Desktop/Mesh/InofitLab")

    target = pywavefront.Wavefront(obj_path_name[0][1], collect_faces=True)
    target_vertices = numpy.array(target.vertices, dtype='f').transpose()

    for template_path in obj_path_name:
        template = pywavefront.Wavefront(template_path[1], collect_faces=True)
        template_vertices = numpy.array(template.vertices,
                                        dtype='f').transpose()
        faces = numpy.array(template.mesh_list[0].faces).transpose()

        rigid_transformation, error = point_sets_fitting.point_sets_fitting(
            template_vertices, target_vertices)

        trainsformation_result = rigid_transformation[
            0:3, 0:3] @ template_vertices + rigid_transformation[0:3,
                                                                 3].reshape(
                                                                     -1, 1)

        print("Original fitting Error of {0} = {1}".format(
            template_path[0],
            utility.calculate_fitting_error(template_vertices,
                                            target_vertices)))
        print("Transformed fitting Error {0}= {1}\n".format(
            template_path[0],
            utility.calculate_fitting_error(trainsformation_result,
                                            target_vertices)))