Skip to content

Commit

Permalink
fix animal calibration, adjust calibration parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
lambdaloop committed Aug 19, 2019
1 parent 8ac08a1 commit 00f1f44
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions anipose/calibrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,32 @@ def load_2d_data(config, calibration_path):
points_raw = out['points']
scores = out['scores']

print(points_raw.shape)
print(scores.shape)

all_points.append(points_raw)
all_scores.append(scores)

all_points = np.vstack(all_points)
all_scores = np.vstack(all_scores)
all_points = np.hstack(all_points)
all_scores = np.hstack(all_scores)

return all_points, all_scores

def process_points_for_calibration(all_points, all_scores):
"""Takes in an array all_points of shape FxCxJx2 and all_scores of shape FxCxJ, where
F: number of frames
"""Takes in an array all_points of shape CxFxJx2 and all_scores of shape CxFxJ, where
C: number of cameras
F: number of frames
J: number of joints"""

assert all_points.shape[3] == 2, \
"points are not 2 dimensional, or shape of points is wrong: {}".format(all_points.shape)

n_frames, n_cams, n_joints, _ = all_points.shape
n_cams, n_frames, n_joints, _ = all_points.shape

points = np.copy(all_points).swapaxes(0, 1).reshape(n_cams, -1, 2)
scores = all_scores.swapaxes(0, 1).reshape(n_cams, -1)
points = np.copy(all_points).reshape(n_cams, -1, 2)
scores = all_scores.reshape(n_cams, -1)

points[scores < 0.98] = np.nan
points[scores < 0.95] = np.nan

num_good = np.sum(~np.isnan(points[:, :, 0]), axis=0)
good = num_good >= 2
Expand Down Expand Up @@ -173,13 +176,18 @@ def process_session(config, session_path):
cgroup.set_camera_sizes_videos(video_list)
error = cgroup.calibrate_rows(all_rows, board,
init_intrinsics=init_stuff,
init_extrinsics=init_stuff)
init_extrinsics=init_stuff,
n_iters=10, error_threshold=3, end_mu=1,
n_samp_iter=100, n_samp_full=2000)

if config['calibration']['animal_calibration']:
all_points, all_scores = load_2d_data(config, calibration_path)
imgp = process_points_for_calibration(all_points, all_scores)
error = cgroup.bundle_adjust(imgp, threshold=10,
ftol=1e-4, loss='huber')
# error = cgroup.bundle_adjust(imgp, threshold=10, ftol=1e-4, loss='huber')
error = cgroup.bundle_adjust_iter(imgp, ftol=1e-4, n_iters=5,
n_samp_iter=100, n_samp_full=1000,
max_nfev=500,
verbose=True)
cgroup.metadata['adjusted'] = True
else:
cgroup.metadata['adjusted'] = False
Expand Down

0 comments on commit 00f1f44

Please sign in to comment.