def test_brown_affine(self):
     """Distortion and correction of pixel coordinates."""
     
     # This is all based on values from liboptv/tests/check_imgcoord.c
     cal = Calibration()
     cal.set_pos(np.r_[0., 0., 40.])
     cal.set_angles(np.r_[0., 0., 0.])
     cal.set_primary_point(np.r_[0., 0., 10.])
     cal.set_glass_vec(np.r_[0., 0., 20.])
     cal.set_radial_distortion(np.zeros(3))
     cal.set_decentering(np.zeros(2))
     cal.set_affine_trans(np.r_[1, 0])
     
     # reference metric positions:
     ref_pos = np.array([
         [0.1, 0.1],
         [1., -1.],
         [-10., 10.]
     ])
     
     # Perfect camera: distortion = identity.
     distorted = distort_arr_brown_affine(ref_pos, cal)
     np.testing.assert_array_almost_equal(distorted, ref_pos)
     
     # Some small radial distortion:
     cal.set_radial_distortion(np.r_[0.001, 0., 0.])
     distorted = distort_arr_brown_affine(ref_pos, cal)
     self.failUnless(np.all(abs(distorted) > abs(ref_pos)))
 def test_full_correction(self):
     """Round trip distortion/correction."""
     # This is all based on values from liboptv/tests/check_imgcoord.c
     cal = Calibration()
     cal.set_pos(np.r_[0., 0., 40.])
     cal.set_angles(np.r_[0., 0., 0.])
     cal.set_primary_point(np.r_[0., 0., 10.])
     cal.set_glass_vec(np.r_[0., 0., 20.])
     cal.set_radial_distortion(np.zeros(3))
     cal.set_decentering(np.zeros(2))
     cal.set_affine_trans(np.r_[1, 0])
     
     # reference metric positions:
     # Note the last value is different than in test_brown_affine() because
     # the iteration does not converge for a point too far out.
     ref_pos = np.array([
         [0.1, 0.1],
         [1., -1.],
         [-5., 5.]
     ])
     
     cal.set_radial_distortion(np.r_[0.001, 0., 0.])
     distorted = distort_arr_brown_affine(ref_pos, cal)
     corrected = distorted_to_flat(distorted, cal) # default tight tolerance
     np.testing.assert_array_almost_equal(ref_pos, corrected, decimal=6)
예제 #3
0
class Test_image_coordinates(unittest.TestCase):
    def setUp(self):
        self.control = ControlParams(4) 
    
        self.calibration = Calibration()
        
    def test_img_coord_typecheck(self):
        
        with self.assertRaises(TypeError):
            list = [[0 for x in range(3)] for x in range(10)]  # initialize a 10x3 list (but not numpy matrix)
            flat_image_coordinates(list, self.control, out=None)
        with self.assertRaises(TypeError):
            flat_image_coordinates(np.empty((10, 2)), self.calibration, self.control.get_multimedia_params(), output=None)
        with self.assertRaises(TypeError):
            image_coordinates(np.empty((10, 3)), self.calibration, self.control.get_multimedia_params(), output=np.zeros((10, 3)))
        with self.assertRaises(TypeError):
            image_coordinates(np.zeros((10, 2)), self.calibration, self.control.get_multimedia_params(), output=np.zeros((10, 2)))
   
    def test_image_coord_regress(self):
        
        self.calibration.set_pos(np.array([0, 0, 40]))
        self.calibration.set_angles(np.array([0, 0, 0]))
        self.calibration.set_primary_point(np.array([0, 0, 10]))
        self.calibration.set_glass_vec(np.array([0, 0, 20]))
        self.calibration.set_radial_distortion(np.array([0, 0, 0]))
        self.calibration.set_decentering(np.array([0, 0]))
        self.calibration.set_affine_trans(np.array([1, 0]))

        self.mult = MultimediaParams(n1=1,
                                     n2=np.array([1]),
                                     n3=1,
                                     d=np.array([1]))
        
        input = np.array([[10., 5., -20.],
                          [10., 5., -20.]])  # vec3d
        output = np.zeros((2, 2))
        
        x = 10. / 6.
        y = x / 2.
        correct_output = np.array([[x, y],
                                   [x, y]])

        flat_image_coordinates(input=input, cal=self.calibration, mult_params=self.mult, output=output)
        np.testing.assert_array_equal(output, correct_output)
        
        output=np.full((2,2), 999.)
        image_coordinates(input=input, cal=self.calibration, mult_params=self.mult, output=output)

        np.testing.assert_array_equal(output, correct_output)
예제 #4
0
class Test_image_coordinates(unittest.TestCase):
    def setUp(self):
        self.control = ControlParams(4)

        self.calibration = Calibration()

    def test_img_coord_typecheck(self):

        with self.assertRaises(TypeError):
            list = [[0 for x in range(3)] for x in range(10)
                    ]  # initialize a 10x3 list (but not numpy matrix)
            flat_image_coordinates(list, self.control, out=None)
        with self.assertRaises(TypeError):
            flat_image_coordinates(np.empty((10, 2)),
                                   self.calibration,
                                   self.control.get_multimedia_params(),
                                   output=None)
        with self.assertRaises(TypeError):
            image_coordinates(np.empty((10, 3)),
                              self.calibration,
                              self.control.get_multimedia_params(),
                              output=np.zeros((10, 3)))
        with self.assertRaises(TypeError):
            image_coordinates(np.zeros((10, 2)),
                              self.calibration,
                              self.control.get_multimedia_params(),
                              output=np.zeros((10, 2)))

    def test_image_coord_regress(self):

        self.calibration.set_pos(np.array([0, 0, 40]))
        self.calibration.set_angles(np.array([0, 0, 0]))
        self.calibration.set_primary_point(np.array([0, 0, 10]))
        self.calibration.set_glass_vec(np.array([0, 0, 20]))
        self.calibration.set_radial_distortion(np.array([0, 0, 0]))
        self.calibration.set_decentering(np.array([0, 0]))
        self.calibration.set_affine_trans(np.array([1, 0]))

        self.mult = MultimediaParams(n1=1,
                                     n2=np.array([1]),
                                     n3=1,
                                     d=np.array([1]))

        input = np.array([[10., 5., -20.], [10., 5., -20.]])  # vec3d
        output = np.zeros((2, 2))

        x = 10. / 6.
        y = x / 2.
        correct_output = np.array([[x, y], [x, y]])

        flat_image_coordinates(input=input,
                               cal=self.calibration,
                               mult_params=self.mult,
                               output=output)
        np.testing.assert_array_equal(output, correct_output)

        output = np.full((2, 2), 999.)
        image_coordinates(input=input,
                          cal=self.calibration,
                          mult_params=self.mult,
                          output=output)

        np.testing.assert_array_equal(output, correct_output)