def pairs_and_their_E(pairs_and_poses): pairs, poses, camera, _, _, _ = pairs_and_poses pairs = list( sorted(zip(pairs.values(), poses.values()), key=lambda x: -len(x[0]))) num_pairs = 20 indices = [np.random.randint(0, len(pairs) - 1) for i in range(num_pairs)] ret_pairs = [] for idx in indices: pair = pairs[idx] p1 = np.array([x for x, _ in pair[0]]) p2 = np.array([x for _, x in pair[0]]) p1 = p1.reshape(-1, p1.shape[-1]) p2 = p2.reshape(-1, p2.shape[-1]) f1 = camera.pixel_bearing_many(p1) f2 = camera.pixel_bearing_many(p2) pose = pair[1] R = pose.get_rotation_matrix() t_x = multiview.cross_product_matrix(pose.get_origin()) e = R.dot(t_x) e /= np.linalg.norm(e) ret_pairs.append((f1, f2, e, pose)) return ret_pairs
def one_pair_and_its_E(pairs_and_poses): pairs, poses, camera, _, _, _ = pairs_and_poses pairs = list(sorted(zip(pairs.values(), poses.values()), key=lambda x: -len(x[0]))) pair = pairs[0] f1 = camera.pixel_bearing_many(np.array([x for x, _ in pair[0]])) f2 = camera.pixel_bearing_many(np.array([x for _, x in pair[0]])) pose = pair[1] R = pose.get_rotation_matrix() t_x = multiview.cross_product_matrix(pose.get_origin()) e = R.dot(t_x) e /= np.linalg.norm(e) return f1, f2, e, pose