A high-performance general-purpose compute library

- Main Page
- Tutorials
- Release Notes
- Examples

Functions
homography
ArrayFire Functions

Homography Estimation More...

## Functions
AFAPI void | homography (array &H, int &inliers, const array &x_src, const array &y_src, const array &x_dst, const array &y_dst, const af_homography_type htype=AF_HOMOGRAPHY_RANSAC, const float inlier_thr=3.f, const unsigned iterations=1000, const dtype otype=f32)
| C++ Interface for Homography estimation.
AFAPI af_err | af_homography (af_array *H, int *inliers, const af_array x_src, const af_array y_src, const af_array x_dst, const af_array y_dst, const af_homography_type htype, const float inlier_thr, const unsigned iterations, const af_dtype otype)
| C Interface wrapper for Homography estimation.

## Detailed Description

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. For the LMedS case, the number of iterations is currently hardcoded to meet the following equation:

\( m = \frac{log(1 - P)}{log[1 - {(1 - \epsilon)}^{p}]}\),

where \( P = 0.99\), \( \epsilon = 40\%\) and \( p = 4\).

## Function Documentation

## ◆ af_homography()

AFAPI af_err af_homography | ( | af_array * | H,
|  | int * | inliers,
|  | const af_array | x_src,
|  | const af_array | y_src,
|  | const af_array | x_dst,
|  | const af_array | y_dst,
|  | const af_homography_type | htype,
|  | const float | inlier_thr,
|  | const unsigned | iterations,
|  | const af_dtype | otype )

C Interface wrapper for Homography estimation.

Parameters

  [out] | H | is a 3x3 array containing the estimated homography.
  [out] | 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.
  [in] | x_src | x coordinates of the source points.
  [in] | y_src | y coordinates of the source points.
  [in] | x_dst | x coordinates of the destination points.
  [in] | y_dst | y coordinates of the destination points.
  [in] | 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.
  [in] | inlier_thr | if htype is AF_HOMOGRAPHY_RANSAC, this parameter will five the maximum L2-distance for a point to be considered an inlier.
  [in] | iterations | 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.
  [in] | otype | the array type for the homography output.

Returns
  AF_SUCCESS if the computation is is successful, otherwise an appropriate error code is returned.

## ◆ homography()

AFAPI void homography | ( | array & | H,
|  | int & | inliers,
|  | const array & | x_src,
|  | const array & | y_src,
|  | const array & | x_dst,
|  | const array & | y_dst,
|  | const af_homography_type | htype = AF_HOMOGRAPHY_RANSAC,
|  | const float | inlier_thr = 3.f,
|  | const unsigned | iterations = 1000,
|  | const dtype | otype = f32 )

C++ Interface for Homography estimation.

Parameters

  [out] | H | is a 3x3 array containing the estimated homography.
  [out] | 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.
  [in] | x_src | x coordinates of the source points.
  [in] | y_src | y coordinates of the source points.
  [in] | x_dst | x coordinates of the destination points.
  [in] | y_dst | y coordinates of the destination points.
  [in] | 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
  [in] | inlier_thr | if htype is AF_HOMOGRAPHY_RANSAC, this parameter will five the maximum L2-distance for a point to be considered an inlier.
  [in] | iterations | 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.
  [in] | otype | the array type for the homography output.