[][src]Function opencv::calib3d::find_homography_ext

pub fn find_homography_ext(
    src_points: &dyn ToInputArray,
    dst_points: &dyn ToInputArray,
    method: i32,
    ransac_reproj_threshold: f64,
    mask: &mut dyn ToOutputArray,
    max_iters: i32,
    confidence: f64
) -> Result<Mat>

Finds a perspective transformation between two planes.

Parameters

  • srcPoints: Coordinates of the points in the original plane, a matrix of the type CV_32FC2 or vector<Point2f> .
  • dstPoints: Coordinates of the points in the target plane, a matrix of the type CV_32FC2 or a vector<Point2f> .
  • method: Method used to compute a homography matrix. The following methods are possible:
  • 0 - a regular method using all the points, i.e., the least squares method
  • RANSAC - RANSAC-based robust method
  • LMEDS - Least-Median robust method
  • RHO - PROSAC-based robust method
  • ransacReprojThreshold: Maximum allowed reprojection error to treat a point pair as an inlier (used in the RANSAC and RHO methods only). That is, if block formula then the point inline formula is considered as an outlier. If srcPoints and dstPoints are measured in pixels, it usually makes sense to set this parameter somewhere in the range of 1 to 10.
  • mask: Optional output mask set by a robust method ( RANSAC or LMEDS ). Note that the input mask values are ignored.
  • maxIters: The maximum number of RANSAC iterations.
  • confidence: Confidence level, between 0 and 1.

The function finds and returns the perspective transformation inline formula between the source and the destination planes:

block formula

so that the back-projection error

block formula

is minimized. If the parameter method is set to the default value 0, the function uses all the point pairs to compute an initial homography estimate with a simple least-squares scheme.

However, if not all of the point pairs ( inline formula, inline formula ) fit the rigid perspective transformation (that is, there are some outliers), this initial estimate will be poor. In this case, you can use one of the three robust methods. The methods RANSAC, LMeDS and RHO try many different random subsets of the corresponding point pairs (of four pairs each, collinear pairs are discarded), estimate the homography matrix using this subset and a simple least-squares algorithm, and then compute the quality/goodness of the computed homography (which is the number of inliers for RANSAC or the least median re-projection error for LMeDS). The best subset is then used to produce the initial estimate of the homography matrix and the mask of inliers/outliers.

Regardless of the method, robust or not, the computed homography matrix is refined further (using inliers only in case of a robust method) with the Levenberg-Marquardt method to reduce the re-projection error even more.

The methods RANSAC and RHO can handle practically any ratio of outliers but need a threshold to distinguish inliers from outliers. The method LMeDS does not need any threshold but it works correctly only when there are more than 50% of inliers. Finally, if there are no outliers and the noise is rather small, use the default method (method=0).

The function is used to find initial intrinsic and extrinsic matrices. Homography matrix is determined up to a scale. Thus, it is normalized so that inline formula. Note that whenever an inline formula matrix cannot be estimated, an empty one will be returned.

See also

getAffineTransform, estimateAffine2D, estimateAffinePartial2D, getPerspectiveTransform, warpPerspective, perspectiveTransform

C++ default parameters

  • method: 0
  • ransac_reproj_threshold: 3
  • mask: noArray()
  • max_iters: 2000
  • confidence: 0.995