示例#1
0
def resect(data, graph, reconstruction, shot_id):
    '''Add a shot to the reconstruction.
    '''
    exif = data.load_exif(shot_id)
    camera_id = exif['camera']
    camera = reconstruction['cameras'][camera_id]

    bs = []
    Xs = []
    for track in graph[shot_id]:
        if track in reconstruction['points']:
            x = graph[track][shot_id]['feature']
            b = multiview.pixel_bearing(x, camera)
            bs.append(b)
            Xs.append(reconstruction['points'][track]['coordinates'])
    bs = np.array(bs)
    Xs = np.array(Xs)
    if len(bs) < 5:
        return False

    threshold = data.config.get('resection_threshold', 0.004)
    T = pyopengv.absolute_pose_ransac(bs, Xs, "KNEIP", 1 - np.cos(threshold),
                                      1000)

    R = T[:, :3]
    t = T[:, 3]

    reprojected_bs = R.T.dot((Xs - t).T).T
    reprojected_bs /= np.linalg.norm(reprojected_bs, axis=1)[:, np.newaxis]

    inliers = np.linalg.norm(reprojected_bs - bs, axis=1) < threshold
    ninliers = sum(inliers)

    print 'Resection', shot_id, 'inliers:', ninliers, '/', len(bs)
    if ninliers >= data.config.get('resection_min_inliers', 15):
        R = cv2.Rodrigues(T[:, :3].T)[0].ravel()
        t = -T[:, :3].T.dot(T[:, 3])
        reconstruction['shots'][shot_id] = {
            "camera": camera_id,
            "rotation": list(R.flat),
            "translation": list(t.flat),
        }
        add_gps_position(data, reconstruction['shots'][shot_id], shot_id)
        bundle_single_view(graph, reconstruction, shot_id, data.config)
        return True
    else:
        return False
示例#2
0
def triangulate_track(track, graph, reconstruction, Rt_by_id, reproj_threshold, min_ray_angle_degrees):
    min_ray_angle = np.radians(min_ray_angle_degrees)
    Rts, bs = [], []

    for shot_id in graph[track]:
        if shot_id in reconstruction["shots"]:
            shot = reconstruction["shots"][shot_id]
            camera = reconstruction["cameras"][shot["camera"]]
            if shot_id not in Rt_by_id:
                Rt_by_id[shot_id] = Rt_from_shot(shot)
            Rts.append(Rt_by_id[shot_id])
            x = graph[track][shot_id]["feature"]
            b = multiview.pixel_bearing(np.array(x), camera)
            bs.append(b)

    if len(Rts) >= 2:
        e, X = csfm.triangulate_bearings(Rts, bs, reproj_threshold, min_ray_angle)
        if X is not None:
            reconstruction["points"][track] = {"coordinates": list(X)}
示例#3
0
def resect(data, graph, reconstruction, shot_id):
    """Add a shot to the reconstruction.
    """
    exif = data.load_exif(shot_id)
    camera_id = exif["camera"]
    camera = reconstruction["cameras"][camera_id]

    bs = []
    Xs = []
    for track in graph[shot_id]:
        if track in reconstruction["points"]:
            x = graph[track][shot_id]["feature"]
            b = multiview.pixel_bearing(x, camera)
            bs.append(b)
            Xs.append(reconstruction["points"][track]["coordinates"])
    bs = np.array(bs)
    Xs = np.array(Xs)
    if len(bs) < 5:
        return False

    threshold = data.config.get("resection_threshold", 0.004)
    T = pyopengv.absolute_pose_ransac(bs, Xs, "KNEIP", 1 - np.cos(threshold), 1000)

    R = T[:, :3]
    t = T[:, 3]

    reprojected_bs = R.T.dot((Xs - t).T).T
    reprojected_bs /= np.linalg.norm(reprojected_bs, axis=1)[:, np.newaxis]

    inliers = np.linalg.norm(reprojected_bs - bs, axis=1) < threshold
    ninliers = sum(inliers)

    print "Resection", shot_id, "inliers:", ninliers, "/", len(bs)
    if ninliers >= data.config.get("resection_min_inliers", 15):
        R = cv2.Rodrigues(T[:, :3].T)[0].ravel()
        t = -T[:, :3].T.dot(T[:, 3])
        reconstruction["shots"][shot_id] = {"camera": camera_id, "rotation": list(R.flat), "translation": list(t.flat)}
        add_gps_position(data, reconstruction["shots"][shot_id], shot_id)
        bundle_single_view(graph, reconstruction, shot_id, data.config)
        return True
    else:
        return False
示例#4
0
def triangulate_track(track, graph, reconstruction, Rt_by_id, reproj_threshold,
                      min_ray_angle_degrees):
    min_ray_angle = np.radians(min_ray_angle_degrees)
    Rts, bs = [], []

    for shot_id in graph[track]:
        if shot_id in reconstruction['shots']:
            shot = reconstruction['shots'][shot_id]
            camera = reconstruction['cameras'][shot['camera']]
            if shot_id not in Rt_by_id:
                Rt_by_id[shot_id] = Rt_from_shot(shot)
            Rts.append(Rt_by_id[shot_id])
            x = graph[track][shot_id]['feature']
            b = multiview.pixel_bearing(np.array(x), camera)
            bs.append(b)

    if len(Rts) >= 2:
        e, X = csfm.triangulate_bearings(Rts, bs, reproj_threshold,
                                         min_ray_angle)
        if X is not None:
            reconstruction['points'][track] = {
                "coordinates": list(X),
            }