def _test_example_intrinsics(self, example): p3c, p2, f, c = (example[k] for k in ['p3c', 'p2', 'f', 'c']) actual_f, actual_c = calculate_intrinsics(np.reshape(p3c, (-1, 3)), np.reshape(p2, (-1, 2))) np.testing.assert_allclose(actual_f, f) np.testing.assert_allclose(actual_c, c) actual_p2 = project(p3c, f, c) np.testing.assert_allclose(actual_p2, p2, atol=1.0)
def check_projections(): from human_pose_util.skeleton import vis2d import matplotlib.pyplot as plt example = dataset[keys[0]] p2 = example['p2'] mins = np.min(p2, axis=1) maxs = np.max(p2, axis=1) n = len(mins) plt.plot(range(n), mins, range(n), maxs) plt.show() p3c = example['p3c'] f = example.attrs['f'] c = example.attrs['c'] actual = np_impl.project(p3c, f, c) idx = -1 plt.figure() vis2d(skeleton, actual[idx]) plt.figure() vis2d(skeleton, p2[idx], linewidth=4) plt.show() print(np.max(np.abs(actual - p2)), np.max(np.abs(p2)))
def apply_consistent_projection(sequence): p3c = sequence['p3c'] f, c = (sequence.attrs[k] for k in ['f', 'c']) sequence['p2'] = np_impl.project(p3c, f=f, c=c)
# raise Exception('Unrecognized skeleton, %s' % skeleton) # else: # return dataset if __name__ == '__main__': import numpy as np from human_pose_util.skeleton import vis3d, vis2d from human_pose_util.transforms.np_impl import transform_frame from human_pose_util.transforms.np_impl import project from skeleton import s14 # from skeleton import s16 from skeleton import s20 import matplotlib.pyplot as plt # dataset = human_eva_dataset(skeleton=s16) example = get_example(list(train_ids())[0]).map( {k: s20.to_s14 for k in ['p2', 'p3c', 'p3w']}) p3w, p3c, p2, r, t, f, c = example['p3w', 'p3c', 'p2', 'r', 't', 'f', 'c'] p3w = p3w[0] p3c = p3c[0] p2 = p2[0] p3c2 = transform_frame(p3w, r, t) print(np.max(np.abs(p3c - p3c2)) / np.max(np.abs(p3c))) p22 = project(p3c, f, c) print(np.max(np.abs(p22 - p2)) / np.max(np.abs(p2))) skeleton = s14 vis3d(skeleton, p3w) vis3d(skeleton, p3c) vis2d(skeleton, p2) plt.show()