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)
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)
def test_single_camera_point_positions(self): """Point positions for a single camera case""" num_cams = 1 # prepare MultimediaParams cpar_file = b'testing_fodder/single_cam/parameters/ptv.par' vpar_file = b'testing_fodder/single_cam/parameters/criteria.par' cpar = ControlParams(num_cams) cpar.read_control_par(cpar_file) mult_params = cpar.get_multimedia_params() vpar = VolumeParams() vpar.read_volume_par(vpar_file) ori_name = b'testing_fodder/single_cam/calibration/cam_1.tif.ori' add_name = b'testing_fodder/single_cam/calibration/cam_1.tif.addpar' calibs = [] # read calibration for each camera from files new_cal = Calibration() new_cal.from_file(ori_file=ori_name, add_file=add_name) calibs.append(new_cal) # 3d point points = np.array([[1, 1, 0], [-1, -1, 0]], dtype=float) targs_plain = [] targs_jigged = [] jigg_amp = 0.4 new_plain_targ = image_coordinates( points, calibs[0], mult_params) targs_plain.append(new_plain_targ) jigged_points = points - np.r_[0, jigg_amp, 0] new_jigged_targs = image_coordinates( jigged_points, calibs[0], mult_params) targs_jigged.append(new_jigged_targs) targs_plain = np.array(targs_plain).transpose(1,0,2) targs_jigged = np.array(targs_jigged).transpose(1,0,2) skew_dist_plain = point_positions(targs_plain, cpar, calibs, vpar) skew_dist_jigged = point_positions(targs_jigged, cpar, calibs, vpar) if np.any(np.linalg.norm(points - skew_dist_plain[0], axis=1) > 1e-6): self.fail('Rays converge on wrong position.') if np.any(np.linalg.norm(jigged_points - skew_dist_jigged[0], axis=1) > 1e-6): self.fail('Rays converge on wrong position after jigging.')
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_single_camera_point_positions(self): """Point positions for a single camera case""" num_cams = 1 # prepare MultimediaParams cpar_file = b'testing_fodder/single_cam/parameters/ptv.par' vpar_file = b'testing_fodder/single_cam/parameters/criteria.par' cpar = ControlParams(num_cams) cpar.read_control_par(cpar_file) mult_params = cpar.get_multimedia_params() vpar = VolumeParams() vpar.read_volume_par(vpar_file) ori_name = b'testing_fodder/single_cam/calibration/cam_1.tif.ori' add_name = b'testing_fodder/single_cam/calibration/cam_1.tif.addpar' calibs = [] # read calibration for each camera from files new_cal = Calibration() new_cal.from_file(ori_file=ori_name, add_file=add_name) calibs.append(new_cal) # 3d point points = np.array([[1, 1, 0], [-1, -1, 0]], dtype=float) targs_plain = [] targs_jigged = [] jigg_amp = 0.4 new_plain_targ = image_coordinates(points, calibs[0], mult_params) targs_plain.append(new_plain_targ) jigged_points = points - np.r_[0, jigg_amp, 0] new_jigged_targs = image_coordinates(jigged_points, calibs[0], mult_params) targs_jigged.append(new_jigged_targs) targs_plain = np.array(targs_plain).transpose(1, 0, 2) targs_jigged = np.array(targs_jigged).transpose(1, 0, 2) skew_dist_plain = point_positions(targs_plain, cpar, calibs, vpar) skew_dist_jigged = point_positions(targs_jigged, cpar, calibs, vpar) if np.any(np.linalg.norm(points - skew_dist_plain[0], axis=1) > 1e-6): self.fail('Rays converge on wrong position.') if np.any( np.linalg.norm(jigged_points - skew_dist_jigged[0], axis=1) > 1e-6): self.fail('Rays converge on wrong position after jigging.')
def test_full_calibration(self): ref_pts = np.array([ a.flatten() for a in np.meshgrid(np.r_[-60:-30:4j], np.r_[0:15:4j], np.r_[0:15:4j]) ]).T # Fake the image points by back-projection targets = convert_arr_metric_to_pixel( image_coordinates(ref_pts, self.cal, self.control.get_multimedia_params()), self.control) # Full calibration works with TargetArray objects, not NumPy. target_array = TargetArray(len(targets)) for i in xrange(len(targets)): target_array[i].set_pnr(i) target_array[i].set_pos(targets[i]) # Perturb the calibration object, then compore result to original. self.cal.set_pos(self.cal.get_pos() + np.r_[15., -15., 15.]) self.cal.set_angles(self.cal.get_angles() + np.r_[-.5, .5, -.5]) ret, used, err_est = full_calibration(self.cal, ref_pts, target_array, self.control) np.testing.assert_array_almost_equal(self.cal.get_angles(), self.orig_cal.get_angles(), decimal=4) np.testing.assert_array_almost_equal(self.cal.get_pos(), self.orig_cal.get_pos(), decimal=3)
def test_full_calibration(self): ref_pts = np.array([a.flatten() for a in np.meshgrid( np.r_[-60:-30:4j], np.r_[0:15:4j], np.r_[0:15:4j])]).T # Fake the image points by back-projection targets = convert_arr_metric_to_pixel(image_coordinates( ref_pts, self.cal, self.control.get_multimedia_params()), self.control) # Full calibration works with TargetArray objects, not NumPy. target_array = TargetArray(len(targets)) for i in xrange(len(targets)): target_array[i].set_pnr(i) target_array[i].set_pos(targets[i]) # Perturb the calibration object, then compore result to original. self.cal.set_pos(self.cal.get_pos() + np.r_[15., -15., 15.]) self.cal.set_angles(self.cal.get_angles() + np.r_[-.5, .5, -.5]) ret, used, err_est = full_calibration( self.cal, ref_pts, target_array, self.control) np.testing.assert_array_almost_equal( self.cal.get_angles(), self.orig_cal.get_angles(), decimal=4) np.testing.assert_array_almost_equal( self.cal.get_pos(), self.orig_cal.get_pos(), decimal=3)
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_match_detection_to_ref(self): """Match detection to reference (sortgrid)""" xyz_input = np.array([(10, 10, 10), (200, 200, 200), (600, 800, 100), (20, 10, 2000), (30, 30, 30)], dtype=float) coords_count = len(xyz_input) xy_img_pts_metric = image_coordinates( xyz_input, self.calibration, self.control.get_multimedia_params()) xy_img_pts_pixel = convert_arr_metric_to_pixel( xy_img_pts_metric, control=self.control) # convert to TargetArray object target_array = TargetArray(coords_count) for i in range(coords_count): target_array[i].set_pnr(i) target_array[i].set_pos( (xy_img_pts_pixel[i][0], xy_img_pts_pixel[i][1])) # create randomized target array indices = range(coords_count) shuffled_indices = range(coords_count) while indices == shuffled_indices: random.shuffle(shuffled_indices) rand_targ_array = TargetArray(coords_count) for i in range(coords_count): rand_targ_array[shuffled_indices[i]].set_pos(target_array[i].pos()) rand_targ_array[shuffled_indices[i]].set_pnr(target_array[i].pnr()) # match detection to reference matched_target_array = match_detection_to_ref(cal=self.calibration, ref_pts=xyz_input, img_pts=rand_targ_array, cparam=self.control) # assert target array is as before for i in range(coords_count): if matched_target_array[i].pos() != target_array[i].pos() \ or matched_target_array[i].pnr() != target_array[i].pnr(): self.fail() # pass ref_pts and img_pts with non-equal lengths with self.assertRaises(ValueError): match_detection_to_ref(cal=self.calibration, ref_pts=xyz_input, img_pts=TargetArray(coords_count - 1), cparam=self.control)
def test_match_detection_to_ref(self): """Match detection to reference (sortgrid)""" xyz_input = np.array([(10, 10, 10), (200, 200, 200), (600, 800, 100), (20, 10, 2000), (30, 30, 30)], dtype=float) coords_count = len(xyz_input) xy_img_pts_metric = image_coordinates( xyz_input, self.calibration, self.control.get_multimedia_params()) xy_img_pts_pixel = convert_arr_metric_to_pixel(xy_img_pts_metric, control=self.control) # convert to TargetArray object target_array = TargetArray(coords_count) for i in range(coords_count): target_array[i].set_pnr(i) target_array[i].set_pos( (xy_img_pts_pixel[i][0], xy_img_pts_pixel[i][1])) # create randomized target array indices = range(coords_count) shuffled_indices = range(coords_count) while indices == shuffled_indices: random.shuffle(shuffled_indices) rand_targ_array = TargetArray(coords_count) for i in range(coords_count): rand_targ_array[shuffled_indices[i]].set_pos(target_array[i].pos()) rand_targ_array[shuffled_indices[i]].set_pnr(target_array[i].pnr()) # match detection to reference matched_target_array = match_detection_to_ref(cal=self.calibration, ref_pts=xyz_input, img_pts=rand_targ_array, cparam=self.control) # assert target array is as before for i in range(coords_count): if matched_target_array[i].pos() != target_array[i].pos() \ or matched_target_array[i].pnr() != target_array[i].pnr(): self.fail() # pass ref_pts and img_pts with non-equal lengths with self.assertRaises(ValueError): match_detection_to_ref(cal=self.calibration, ref_pts=xyz_input, img_pts=TargetArray(coords_count - 1), cparam=self.control)
def _project_cal_points(self, i_cam, color="yellow"): x, y = [], [] for row in self.cal_points: projected = image_coordinates(np.atleast_2d(row['pos']), \ self.cals[i_cam], self.cpar.get_multimedia_params()) pos = convert_arr_metric_to_pixel(projected, self.cpar) x.append(pos[0][0]) y.append(pos[0][1]) # x.append(x1) # y.append(y1) self.drawcross("init_x", "init_y", x, y, color, 3, i_cam=i_cam) self.status_text = 'Initial guess finished.'
def test_full_corresp(self): """Full scene correspondences""" print "about to dump core" cpar = ControlParams(4) cpar.read_control_par("testing_fodder/corresp/control.par") vpar = VolumeParams() vpar.read_volume_par("testing_fodder/corresp/criteria.par") # Cameras are at so high angles that opposing cameras don't see each # other in the normal air-glass-water setting. cpar.get_multimedia_params().set_layers([1.0001], [1.]) cpar.get_multimedia_params().set_n3(1.0001) cals = [] img_pts = [] corrected = [] for c in xrange(4): cal = Calibration() cal.from_file( "testing_fodder/calibration/sym_cam%d.tif.ori" % (c + 1), "testing_fodder/calibration/cam1.tif.addpar") cals.append(cal) # Generate test targets. targs = TargetArray(16) for row, col in np.ndindex(4, 4): targ_ix = row*4 + col # Avoid symmetric case: if (c % 2): targ_ix = 15 - targ_ix targ = targs[targ_ix] pos3d = 10*np.array([[col, row, 0]], dtype=np.float64) pos2d = image_coordinates( pos3d, cal, cpar.get_multimedia_params()) targ.set_pos(convert_arr_metric_to_pixel(pos2d, cpar)[0]) targ.set_pnr(targ_ix) targ.set_pixel_counts(25, 5, 5) targ.set_sum_grey_value(10) img_pts.append(targs) mc = MatchedCoords(targs, cpar, cal) corrected.append(mc) sorted_pos, sorted_corresp, num_targs = correspondences( img_pts, corrected, cals, vpar, cpar) self.failUnlessEqual(num_targs, 16)
def test_full_corresp(self): """Full scene correspondences""" cpar = ControlParams(4) cpar.read_control_par(r"testing_fodder/corresp/control.par") vpar = VolumeParams() vpar.read_volume_par(r"testing_fodder/corresp/criteria.par") # Cameras are at so high angles that opposing cameras don't see each # other in the normal air-glass-water setting. cpar.get_multimedia_params().set_layers([1.0001], [1.]) cpar.get_multimedia_params().set_n3(1.0001) cals = [] img_pts = [] corrected = [] for c in xrange(4): cal = Calibration() cal.from_file( "testing_fodder/calibration/sym_cam%d.tif.ori" % (c + 1), "testing_fodder/calibration/cam1.tif.addpar") cals.append(cal) # Generate test targets. targs = TargetArray(16) for row, col in np.ndindex(4, 4): targ_ix = row * 4 + col # Avoid symmetric case: if (c % 2): targ_ix = 15 - targ_ix targ = targs[targ_ix] pos3d = 10 * np.array([[col, row, 0]], dtype=np.float64) pos2d = image_coordinates(pos3d, cal, cpar.get_multimedia_params()) targ.set_pos(convert_arr_metric_to_pixel(pos2d, cpar)[0]) targ.set_pnr(targ_ix) targ.set_pixel_counts(25, 5, 5) targ.set_sum_grey_value(10) img_pts.append(targs) mc = MatchedCoords(targs, cpar, cal) corrected.append(mc) sorted_pos, sorted_corresp, num_targs = correspondences( img_pts, corrected, cals, vpar, cpar) self.failUnlessEqual(num_targs, 16)
def test_single_cam_corresp(self): """Single camera correspondence""" cpar = ControlParams(1) cpar.read_control_par(b"testing_fodder/single_cam/parameters/ptv.par") vpar = VolumeParams() vpar.read_volume_par(b"testing_fodder/single_cam/parameters/criteria.par") # Cameras are at so high angles that opposing cameras don't see each # other in the normal air-glass-water setting. cpar.get_multimedia_params().set_layers([1.], [1.]) cpar.get_multimedia_params().set_n3(1.) cals = [] img_pts = [] corrected = [] cal = Calibration() cal.from_file( b"testing_fodder/single_cam/calibration/cam_1.tif.ori", b"testing_fodder/single_cam/calibration/cam_1.tif.addpar") cals.append(cal) # Generate test targets. targs = TargetArray(9) for row, col in np.ndindex(3, 3): targ_ix = row*3 + col targ = targs[targ_ix] pos3d = 10*np.array([[col, row, 0]], dtype=np.float64) pos2d = image_coordinates( pos3d, cal, cpar.get_multimedia_params()) targ.set_pos(convert_arr_metric_to_pixel(pos2d, cpar)[0]) targ.set_pnr(targ_ix) targ.set_pixel_counts(25, 5, 5) targ.set_sum_grey_value(10) img_pts.append(targs) mc = MatchedCoords(targs, cpar, cal) corrected.append(mc) _, _, num_targs = correspondences( img_pts, corrected, cals, vpar, cpar) self.failUnlessEqual(num_targs, 9)
def test_single_cam_corresp(self): """Single camera correspondence""" cpar = ControlParams(1) cpar.read_control_par("testing_fodder/single_cam/parameters/ptv.par") vpar = VolumeParams() vpar.read_volume_par( "testing_fodder/single_cam/parameters/criteria.par") # Cameras are at so high angles that opposing cameras don't see each # other in the normal air-glass-water setting. cpar.get_multimedia_params().set_layers([1.], [1.]) cpar.get_multimedia_params().set_n3(1.) cals = [] img_pts = [] corrected = [] cal = Calibration() cal.from_file( "testing_fodder/single_cam/calibration/cam_1.tif.ori", "testing_fodder/single_cam/calibration/cam_1.tif.addpar") cals.append(cal) # Generate test targets. targs = TargetArray(9) for row, col in np.ndindex(3, 3): targ_ix = row * 3 + col targ = targs[targ_ix] pos3d = 10 * np.array([[col, row, 0]], dtype=np.float64) pos2d = image_coordinates(pos3d, cal, cpar.get_multimedia_params()) targ.set_pos(convert_arr_metric_to_pixel(pos2d, cpar)[0]) targ.set_pnr(targ_ix) targ.set_pixel_counts(25, 5, 5) targ.set_sum_grey_value(10) img_pts.append(targs) mc = MatchedCoords(targs, cpar, cal) corrected.append(mc) sorted_pos, sorted_corresp, num_targs = correspondences( img_pts, corrected, cals, vpar, cpar) self.failUnlessEqual(num_targs, 9)
def test_external_calibration(self): """External calibration using clicked points.""" ref_pts = np.array([[-40., -25., 8.], [40., -15., 0.], [40., 15., 0.], [40., 0., 8.]]) # Fake the image points by back-projection targets = convert_arr_metric_to_pixel( image_coordinates(ref_pts, self.cal, self.control.get_multimedia_params()), self.control) # Jigg the fake detections to give raw_orient some challenge. targets[:, 1] -= 0.1 self.assertTrue( external_calibration(self.cal, ref_pts, targets, self.control)) np.testing.assert_array_almost_equal(self.cal.get_angles(), self.orig_cal.get_angles(), decimal=4) np.testing.assert_array_almost_equal(self.cal.get_pos(), self.orig_cal.get_pos(), decimal=3)
def test_external_calibration(self): """External calibration using clicked points.""" ref_pts = np.array([ [-40., -25., 8.], [ 40., -15., 0.], [ 40., 15., 0.], [ 40., 0., 8.]]) # Fake the image points by back-projection targets = convert_arr_metric_to_pixel(image_coordinates( ref_pts, self.cal, self.control.get_multimedia_params()), self.control) # Jigg the fake detections to give raw_orient some challenge. targets[:,1] -= 0.1 self.assertTrue(external_calibration( self.cal, ref_pts, targets, self.control)) np.testing.assert_array_almost_equal( self.cal.get_angles(), self.orig_cal.get_angles(), decimal=4) np.testing.assert_array_almost_equal( self.cal.get_pos(), self.orig_cal.get_pos(), decimal=3)
part_traject = np.zeros((num_frames, 3)) part_traject[:, 0] = np.r_[:num_frames] * velocity # Find targets on each camera. cpar = ControlParams(3) cpar.read_control_par("testing_fodder/track/parameters/control_newpart.par") targs = [] for cam in xrange(num_cams): cal = Calibration() cal.from_file("testing_fodder/cal/sym_cam%d.tif.ori" % (cam + 1), "testing_fodder/cal/cam1.tif.addpar") targs.append( convert_arr_metric_to_pixel( image_coordinates(part_traject, cal, cpar.get_multimedia_params()), cpar)) for frame in xrange(num_frames): # write 3D positions: with open("testing_fodder/track/res_orig/particles.%d" % (frame + 1), "w") as outfile: # Note correspondence to the single target in each frame. outfile.writelines([ str(1) + "\n", "{:5d}{:10.3f}{:10.3f}{:10.3f}{:5d}{:5d}{:5d}{:5d}\n".format( 1, part_traject[frame, 0], part_traject[frame, 1], part_traject[frame, 1], 0, 0, 0, 0) ]) # write associated targets from all cameras:
velocity = 0.01 part_traject = np.zeros((num_frames,3)) part_traject[:,0] = np.r_[:num_frames]*velocity # Find targets on each camera. cpar = ControlParams(3) cpar.read_control_par("testing_fodder/track/parameters/control_newpart.par") targs = [] for cam in xrange(num_cams): cal = Calibration() cal.from_file( "testing_fodder/cal/sym_cam%d.tif.ori" % (cam + 1), "testing_fodder/cal/cam1.tif.addpar") targs.append(convert_arr_metric_to_pixel(image_coordinates( part_traject, cal, cpar.get_multimedia_params()), cpar)) for frame in xrange(num_frames): # write 3D positions: with open("testing_fodder/track/res_orig/particles.%d" % (frame + 1), "w") as outfile: # Note correspondence to the single target in each frame. outfile.writelines([ str(1) + "\n", "{:5d}{:10.3f}{:10.3f}{:10.3f}{:5d}{:5d}{:5d}{:5d}\n".format( 1, part_traject[frame,0], part_traject[frame,1], part_traject[frame,1], 0, 0, 0, 0)]) # write associated targets from all cameras: for cam in xrange(num_cams): with open("testing_fodder/track/newpart/cam%d.%04d_targets" \ % (cam + 1, frame + 1), "w") as outfile:
def test_point_positions(self): """Point positions""" # prepare MultimediaParams mult_params = self.control.get_multimedia_params() mult_params.set_n1(1.) mult_params.set_layers(np.array([1.]), np.array([1.])) mult_params.set_n3(1.) # 3d point points = np.array([[17, 42, 0], [17, 42, 0]], dtype=float) num_cams = 4 ori_tmpl = r'testing_fodder/calibration/sym_cam{cam_num}.tif.ori' add_file = r'testing_fodder/calibration/cam1.tif.addpar' calibs = [] targs_plain = [] targs_jigged = [] jigg_amp = 0.5 # read calibration for each camera from files for cam in range(num_cams): ori_name = ori_tmpl.format(cam_num=cam + 1) new_cal = Calibration() new_cal.from_file(ori_file=ori_name, add_file=add_file) calibs.append(new_cal) for cam_num, cam_cal in enumerate(calibs): new_plain_targ = image_coordinates( points, cam_cal, self.control.get_multimedia_params()) targs_plain.append(new_plain_targ) if (cam_num % 2) == 0: jigged_points = points - np.r_[0, jigg_amp, 0] else: jigged_points = points + np.r_[0, jigg_amp, 0] new_jigged_targs = image_coordinates( jigged_points, cam_cal, self.control.get_multimedia_params()) targs_jigged.append(new_jigged_targs) targs_plain = np.array(targs_plain).transpose(1, 0, 2) targs_jigged = np.array(targs_jigged).transpose(1, 0, 2) skew_dist_plain = point_positions(targs_plain, self.control, calibs) skew_dist_jigged = point_positions(targs_jigged, self.control, calibs) if np.any(skew_dist_plain[1] > 1e-10): self.fail(('skew distance of target#{targ_num} ' \ + 'is more than allowed').format( targ_num=np.nonzero(skew_dist_plain[1] > 1e-10)[0][0])) if np.any(np.linalg.norm(points - skew_dist_plain[0], axis=1) > 1e-6): self.fail('Rays converge on wrong position.') if np.any(skew_dist_jigged[1] > 0.7): self.fail(('skew distance of target#{targ_num} ' \ + 'is more than allowed').format( targ_num=np.nonzero(skew_dist_jigged[1] > 1e-10)[0][0])) if np.any(np.linalg.norm(points - skew_dist_jigged[0], axis=1) > 0.1): self.fail('Rays converge on wrong position after jigging.')
def test_point_positions(self): """Point positions""" # prepare MultimediaParams mult_params = self.control.get_multimedia_params() mult_params.set_n1(1.) mult_params.set_layers(np.array([1.]), np.array([1.])) mult_params.set_n3(1.) # 3d point points = np.array([[17, 42, 0], [17, 42, 0]], dtype=float) num_cams = 4 ori_tmpl = r'testing_fodder/calibration/sym_cam{cam_num}.tif.ori' add_file = r'testing_fodder/calibration/cam1.tif.addpar' calibs = [] targs_plain = [] targs_jigged = [] jigg_amp = 0.5 # read calibration for each camera from files for cam in range(num_cams): ori_name = ori_tmpl.format(cam_num=cam + 1) new_cal = Calibration() new_cal.from_file(ori_file=ori_name, add_file=add_file) calibs.append(new_cal) for cam_num, cam_cal in enumerate(calibs): new_plain_targ = image_coordinates( points, cam_cal, self.control.get_multimedia_params()) targs_plain.append(new_plain_targ) if (cam_num % 2) == 0: jigged_points = points - np.r_[0, jigg_amp, 0] else: jigged_points = points + np.r_[0, jigg_amp, 0] new_jigged_targs = image_coordinates( jigged_points, cam_cal, self.control.get_multimedia_params()) targs_jigged.append(new_jigged_targs) targs_plain = np.array(targs_plain).transpose(1,0,2) targs_jigged = np.array(targs_jigged).transpose(1,0,2) skew_dist_plain = point_positions(targs_plain, self.control, calibs) skew_dist_jigged = point_positions(targs_jigged, self.control, calibs) if np.any(skew_dist_plain[1] > 1e-10): self.fail(('skew distance of target#{targ_num} ' \ + 'is more than allowed').format( targ_num=np.nonzero(skew_dist_plain[1] > 1e-10)[0][0])) if np.any(np.linalg.norm(points - skew_dist_plain[0], axis=1) > 1e-6): self.fail('Rays converge on wrong position.') if np.any(skew_dist_jigged[1] > 0.7): self.fail(('skew distance of target#{targ_num} ' \ + 'is more than allowed').format( targ_num=np.nonzero(skew_dist_jigged[1] > 1e-10)[0][0])) if np.any(np.linalg.norm(points - skew_dist_jigged[0], axis=1) > 0.1): self.fail('Rays converge on wrong position after jigging.')