def camera_error(rpc, x0, y0, w, h, n_learn, n_test):
    """
    Measure the accuracy of RPC's projective approximation.

    Args:
        rpc: instance of the rpc_model.RPCModel class
        x0, y0, w, h: four integers definig a rectangular region of interest
            (ROI) in the first view. (x0, y0) is the top-left corner, and (w,
            h) are the dimensions of the rectangle. The keypoints used for
            estimation and evaluation are located in that ROI.
        n_learn: number of points sampled in each of the 3 directions to
            generate 3D-->2D correspondences constraints for projective matrix
            estimation
        n_test: number of points sampled in each of the 3 directions to
            generate 3D points used to test the accuracy of the projective
            matrix
    Returns:
        A float value measuring the accuracy of the projective model. Smaller
        is better.

        This value is the biggest euclidean distance, among all the 'test
        points', between a point projected on the image with the approximated
        matrix and the corresponding projected point with the rpc.
    """

    # step 1: compute the projective model that best fits this range
    X, x = rpc_utils.world_to_image_correspondences_from_rpc(rpc,
                                                        x0, y0, w, h, n_learn)
    P = estimation.camera_matrix(X, x)

    # step 2: compute the error made by the projective model
    X, x = rpc_utils.world_to_image_correspondences_from_rpc(rpc,
                                                        x0, y0, w, h, n_test)
    err = evaluation.camera_matrix(X, x)
    return err
Example #2
0
def approximate_rpc_as_projective(rpc_model,
                                  col_range,
                                  lin_range,
                                  alt_range,
                                  verbose=False):
    """
    Returns a least-square approximation of the RPC functions as a projection
    matrix. The approximation is optimized on a sampling of the 3D region
    defined by the altitudes in alt_range and the image tile defined by
    col_range and lin_range.
    """
    ### step 1: generate cartesian coordinates of 3d points used to fit the
    ###         best projection matrix
    # get mesh points and convert them to geodetic then to geocentric
    # coordinates
    cols, lins, alts = generate_point_mesh(col_range, lin_range, alt_range)
    lons, lats, alts = rpc_model.direct_estimate(cols, lins, alts)
    x, y, z = geographiclib.geodetic_to_geocentric(lats, lons, alts)

    ### step 2: estimate the camera projection matrix from corresponding
    # 3-space and image entities
    world_points = np.vstack([x, y, z]).T
    image_points = np.vstack([cols, lins]).T
    P = estimation.camera_matrix(world_points, image_points)

    ### step 3: for debug, test the approximation error
    if verbose:
        # compute the projection error made by the computed matrix P, on the
        # used learning points
        colPROJ = np.zeros(len(x))
        linPROJ = np.zeros(len(x))
        for i in xrange(len(x)):
            v = np.dot(P, [[x[i]], [y[i]], [z[i]], [1]])
            colPROJ[i] = v[0] / v[2]
            linPROJ[i] = v[1] / v[2]

        print 'approximate_rpc_as_projective: (min, max, mean)'
        print_distance_between_vectors(cols, colPROJ, 'cols')
        print_distance_between_vectors(lins, linPROJ, 'rows')

    return P
Example #3
0
def approximate_rpc_as_projective(rpc_model, col_range, lin_range, alt_range,
        verbose=False):
    """
    Returns a least-square approximation of the RPC functions as a projection
    matrix. The approximation is optimized on a sampling of the 3D region
    defined by the altitudes in alt_range and the image tile defined by
    col_range and lin_range.
    """
    ### step 1: generate cartesian coordinates of 3d points used to fit the
    ###         best projection matrix
    # get mesh points and convert them to geodetic then to geocentric
    # coordinates
    cols, lins, alts = generate_point_mesh(col_range, lin_range, alt_range)
    lons, lats, alts = rpc_model.direct_estimate(cols, lins, alts)
    x, y, z = geographiclib.geodetic_to_geocentric(lats, lons, alts)

    ### step 2: estimate the camera projection matrix from corresponding
    # 3-space and image entities
    world_points = np.vstack([x, y, z]).T
    image_points = np.vstack([cols, lins]).T
    P = estimation.camera_matrix(world_points, image_points)

    ### step 3: for debug, test the approximation error
    if verbose:
        # compute the projection error made by the computed matrix P, on the
        # used learning points
        colPROJ = np.zeros(len(x))
        linPROJ = np.zeros(len(x))
        for i in xrange(len(x)):
            v = np.dot(P, [[x[i]],[y[i]],[z[i]],[1]])
            colPROJ[i] = v[0]/v[2]
            linPROJ[i] = v[1]/v[2]

        print 'approximate_rpc_as_projective: (min, max, mean)'
        print_distance_between_vectors(cols, colPROJ, 'cols')
        print_distance_between_vectors(lins, linPROJ, 'rows')

    return P