Open Declaration Mat org.opencv.calib3d.Calib3d.findHomography(MatOfPoint2f srcPoints, MatOfPoint2f dstPoints, int method, double ransacReprojThreshold)
Finds a perspective transformation between two planes.
The functions find and return the perspective transformation H between the source and the destination planes:
s_i [x'_i y'_i 1] ~ H [x_i y_i 1]
so that the back-projection error
sum _i(x'_i- (h_11 x_i + h_12 y_i + h_13)/(h_(31) x_i + h_32 y_i + h_33))^2+ (y'_i- (h_21 x_i + h_22 y_i + h_23)/(h_(31) x_i + h_32 y_i + h_33))^2
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 (srcPoints_i,dstPoints_i) 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 two robust methods. Both methods, RANSAC and LMeDS, try many different random subsets of the corresponding point pairs (of four pairs each), estimate the homography matrix using this subset and a simple least-square algorithm, and then compute the quality/goodness of the computed homography (which is the number of inliers for RANSAC or the 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 method RANSAC can handle practically any ratio of outliers but it needs 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 h_33=1.
Parameters:
srcPoints Coordinates of the points in the original plane, a matrix of the type CV_32FC2 or vector.
dstPoints Coordinates of the points in the target plane, a matrix of the type CV_32FC2 or a vector.
method Method used to computed a homography matrix. The following methods are possible:
0 - a regular method using all the points
CV_RANSAC - RANSAC-based robust method
CV_LMEDS - Least-Median robust method
ransacReprojThreshold Maximum allowed reprojection error to treat a point pair as an inlier (used in the RANSAC method only). That is, if
| dstPoints _i - convertPointsHomogeneous(H * srcPoints _i)| > ransacReprojThreshold
then the point i is considered 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.
See Also:
org.opencv.calib3d.Calib3d.findHomography
org.opencv.imgproc.Imgproc.warpPerspective
org.opencv.core.Core.perspectiveTransform
org.opencv.video.Video.estimateRigidTransform
org.opencv.imgproc.Imgproc.getAffineTransform
org.opencv.imgproc.Imgproc.getPerspectiveTransform
Finds a perspective transformation between two planes.
The functions find and return the perspective transformation H between the source and the destination planes:
s_i [x'_i y'_i 1] ~ H [x_i y_i 1]
so that the back-projection error
sum _i(x'_i- (h_11 x_i + h_12 y_i + h_13)/(h_(31) x_i + h_32 y_i + h_33))^2+ (y'_i- (h_21 x_i + h_22 y_i + h_23)/(h_(31) x_i + h_32 y_i + h_33))^2
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 (srcPoints_i,dstPoints_i) 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 two robust methods. Both methods, RANSAC and LMeDS, try many different random subsets of the corresponding point pairs (of four pairs each), estimate the homography matrix using this subset and a simple least-square algorithm, and then compute the quality/goodness of the computed homography (which is the number of inliers for RANSAC or the 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 method RANSAC can handle practically any ratio of outliers but it needs 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 h_33=1.
Parameters:
srcPoints Coordinates of the points in the original plane, a matrix of the type CV_32FC2 or vector.
dstPoints Coordinates of the points in the target plane, a matrix of the type CV_32FC2 or a vector.
method Method used to computed a homography matrix. The following methods are possible:
0 - a regular method using all the points
CV_RANSAC - RANSAC-based robust method
CV_LMEDS - Least-Median robust method
ransacReprojThreshold Maximum allowed reprojection error to treat a point pair as an inlier (used in the RANSAC method only). That is, if
| dstPoints _i - convertPointsHomogeneous(H * srcPoints _i)| > ransacReprojThreshold
then the point i is considered 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.
See Also:
org.opencv.calib3d.Calib3d.findHomography
org.opencv.imgproc.Imgproc.warpPerspective
org.opencv.core.Core.perspectiveTransform
org.opencv.video.Video.estimateRigidTransform
org.opencv.imgproc.Imgproc.getAffineTransform
org.opencv.imgproc.Imgproc.getPerspectiveTransform