Function arrayfire::homography [] [src]

pub fn homography<OutType: HasAfEnum>(
    x_src: &Array,
    y_src: &Array,
    x_dst: &Array,
    y_dst: &Array,
    htype: HomographyType,
    inlier_thr: f32,
    iterations: u32
) -> (Array, i32)

Homography estimation

Homography estimation find a perspective transform between two sets of 2D points. Currently, two methods are supported for the estimation, RANSAC (RANdom SAmple Consensus) and LMedS (Least Median of Squares). Both methods work by randomly selecting a subset of 4 points of the set of source points, computing the eigenvectors of that set and finding the perspective transform. The process is repeated several times, a maximum of times given by the value passed to the iterations arguments for RANSAC (for the CPU backend, usually less than that, depending on the quality of the dataset, but for CUDA and OpenCL backends the transformation will be computed exactly the amount of times passed via the iterations parameter), the returned value is the one that matches the best number of inliers, which are all of the points that fall within a maximum L2 distance from the value passed to the inlier_thr argument.

Parameters

  • x_src is the x coordinates of the source points.
  • y_src is the y coordinates of the source points.
  • x_dst is the x coordinates of the destination points.
  • y_dst is the y coordinates of the destination points.
  • htype can be AF_HOMOGRAPHY_RANSAC, for which a RANdom SAmple Consensus will be used to evaluate the homography quality (e.g., number of inliers), or AF_HOMOGRAPHY_LMEDS, which will use Least Median of Squares method to evaluate homography quality
  • inlier_thr - if htype is AF_HOMOGRAPHY_RANSAC, this parameter will five the maximum L2-distance for a point to be considered an inlier.
  • iterations is the maximum number of iterations when htype is AF_HOMOGRAPHY_RANSAC and backend is CPU,if backend is CUDA or OpenCL, iterations is the total number of iterations, an iteration is a selection of 4 random points for which the homography is estimated and evaluated for number of inliers.
  • otype is the array type for the homography output.

Return Values

Returns a tuple of Array and int.

  • H is a 3x3 array containing the estimated homography.
  • inliers is the number of inliers that the homography was estimated to comprise, in the case that htype is AF_HOMOGRAPHY_RANSAC, a higher inlier_thr value will increase the estimated inliers. Note that if the number of inliers is too low, it is likely that a bad homography will be returned.