def test_two_cameras(self): ori_tmpl = "testing_fodder/calibration/sym_cam{cam_num}.tif.ori" add_file = "testing_fodder/calibration/cam1.tif.addpar" orig_cal = Calibration() orig_cal.from_file( ori_tmpl.format(cam_num=1).encode(), add_file.encode()) proj_cal = Calibration() proj_cal.from_file( ori_tmpl.format(cam_num=3).encode(), add_file.encode()) # reorient cams: orig_cal.set_angles(np.r_[0., -np.pi / 4., 0.]) proj_cal.set_angles(np.r_[0., 3 * np.pi / 4., 0.]) cpar = ControlParams(4) cpar.read_control_par(b"testing_fodder/corresp/control.par") sens_size = cpar.get_image_size() vpar = VolumeParams() vpar.read_volume_par(b"testing_fodder/corresp/criteria.par") vpar.set_Zmin_lay([-10, -10]) vpar.set_Zmax_lay([10, 10]) mult_params = cpar.get_multimedia_params() mult_params.set_n1(1.) mult_params.set_layers(np.array([1.]), np.array([1.])) mult_params.set_n3(1.) # Central point translates to central point because cameras point # directly at each other. mid = np.r_[sens_size] / 2. line = epipolar_curve(mid, orig_cal, proj_cal, 5, cpar, vpar) self.failUnless(np.all(abs(line - mid) < 1e-6)) # An equatorial point draws a latitude. line = epipolar_curve(mid - np.r_[100., 0.], orig_cal, proj_cal, 5, cpar, vpar) np.testing.assert_array_equal(np.argsort(line[:, 0]), np.arange(5)[::-1]) self.failUnless(np.all(abs(line[:, 1] - mid[1]) < 1e-6))
def test_two_cameras(self): ori_tmpl = "testing_fodder/calibration/sym_cam{cam_num}.tif.ori" add_file = "testing_fodder/calibration/cam1.tif.addpar" orig_cal = Calibration() orig_cal.from_file(ori_tmpl.format(cam_num=1).encode(), add_file.encode()) proj_cal = Calibration() proj_cal.from_file(ori_tmpl.format(cam_num=3).encode(), add_file.encode()) # reorient cams: orig_cal.set_angles(np.r_[0., -np.pi/4., 0.]) proj_cal.set_angles(np.r_[0., 3*np.pi/4., 0.]) cpar = ControlParams(4) cpar.read_control_par(b"testing_fodder/corresp/control.par") sens_size = cpar.get_image_size() vpar = VolumeParams() vpar.read_volume_par(b"testing_fodder/corresp/criteria.par") vpar.set_Zmin_lay([-10, -10]) vpar.set_Zmax_lay([10, 10]) mult_params = cpar.get_multimedia_params() mult_params.set_n1(1.) mult_params.set_layers(np.array([1.]), np.array([1.])) mult_params.set_n3(1.) # Central point translates to central point because cameras point # directly at each other. mid = np.r_[sens_size]/2. line = epipolar_curve(mid, orig_cal, proj_cal, 5, cpar, vpar) self.failUnless(np.all(abs(line - mid) < 1e-6)) # An equatorial point draws a latitude. line = epipolar_curve( mid - np.r_[100., 0.], orig_cal, proj_cal, 5, cpar, vpar) np.testing.assert_array_equal(np.argsort(line[:,0]), np.arange(5)[::-1]) self.failUnless(np.all(abs(line[:,1] - mid[1]) < 1e-6))
class Test_VolumeParams(unittest.TestCase): def setUp(self): self.input_volume_par_file_name = "testing_fodder/volume_parameters/volume.par" self.temp_output_directory = "testing_fodder/volume_parameters/testing_output" # create a temporary output directory (will be deleted by the end of test) if not os.path.exists(self.temp_output_directory): os.makedirs(self.temp_output_directory) # create an instance of VolumeParams class self.vol_obj = VolumeParams() def test_read_volume(self): # Fill the VolumeParams object with parameters from test file self.vol_obj.read_volume_par(self.input_volume_par_file_name) # check that all parameters are equal to the contents of test file numpy.testing.assert_array_equal(numpy.array([111.111, 222.222]), self.vol_obj.get_X_lay()) numpy.testing.assert_array_equal(numpy.array([333.333, 444.444]), self.vol_obj.get_Zmin_lay()) numpy.testing.assert_array_equal(numpy.array([555.555, 666.666]), self.vol_obj.get_Zmax_lay()) self.failUnless(self.vol_obj.get_cnx() == 777.777) self.failUnless(self.vol_obj.get_cny() == 888.888) self.failUnless(self.vol_obj.get_cn() == 999.999) self.failUnless(self.vol_obj.get_csumg() == 1010.1010) self.failUnless(self.vol_obj.get_corrmin() == 1111.1111) self.failUnless(self.vol_obj.get_eps0() == 1212.1212) def test_setters(self): xlay = numpy.array([111.1, 222.2]) self.vol_obj.set_X_lay(xlay) numpy.testing.assert_array_equal(xlay, self.vol_obj.get_X_lay()) zmin = numpy.array([333.3, 444.4]) self.vol_obj.set_Zmin_lay(zmin) numpy.testing.assert_array_equal(zmin, self.vol_obj.get_Zmin_lay()) zmax = numpy.array([555.5, 666.6]) self.vol_obj.set_Zmax_lay(zmax) numpy.testing.assert_array_equal(zmax, self.vol_obj.get_Zmax_lay()) self.vol_obj.set_cn(1) self.failUnless(self.vol_obj.get_cn() == 1) self.vol_obj.set_cnx(2) self.failUnless(self.vol_obj.get_cnx() == 2) self.vol_obj.set_cny(3) self.failUnless(self.vol_obj.get_cny() == 3) self.vol_obj.set_csumg(4) self.failUnless(self.vol_obj.get_csumg() == 4) self.vol_obj.set_eps0(5) self.failUnless(self.vol_obj.get_eps0() == 5) self.vol_obj.set_corrmin(6) self.failUnless(self.vol_obj.get_corrmin() == 6) def test_init_kwargs(self): """Initialize volume parameters with keyword arguments""" xlay = numpy.array([111.1, 222.2]) zlay = [r_[333.3, 555.5], r_[444.4, 666.6]] zmin, zmax = zip(*zlay) vol_obj = VolumeParams(x_span=xlay, z_spans=zlay, pixels_tot=1, pixels_x=2, pixels_y=3, ref_gray=4, epipolar_band=5, min_correlation=6) numpy.testing.assert_array_equal(xlay, vol_obj.get_X_lay()) numpy.testing.assert_array_equal(zmin, vol_obj.get_Zmin_lay()) numpy.testing.assert_array_equal(zmax, vol_obj.get_Zmax_lay()) self.failUnless(vol_obj.get_cn() == 1) self.failUnless(vol_obj.get_cnx() == 2) self.failUnless(vol_obj.get_cny() == 3) self.failUnless(vol_obj.get_csumg() == 4) self.failUnless(vol_obj.get_eps0() == 5) self.failUnless(vol_obj.get_corrmin() == 6) # testing __richcmp__ comparison method of VolumeParams class def test_rich_compare(self): self.vol_obj2 = VolumeParams() self.vol_obj2.read_volume_par(self.input_volume_par_file_name) self.vol_obj3 = VolumeParams() self.vol_obj3.read_volume_par(self.input_volume_par_file_name) self.failUnless(self.vol_obj2 == self.vol_obj3) self.failIf(self.vol_obj2 != self.vol_obj3) self.vol_obj2.set_cn(-999) self.failUnless(self.vol_obj2 != self.vol_obj3) self.failIf(self.vol_obj2 == self.vol_obj3) with self.assertRaises(TypeError): var = (self.vol_obj2 < self.vol_obj3) def tearDown(self): # remove the testing output directory and its files shutil.rmtree(self.temp_output_directory)