FindHomography() публичный статический Метод

Use the specific method to find perspective transformation H=||h_ij|| between the source and the destination planes
public static FindHomography ( Matrix srcPoints, Matrix dstPoints, CvEnum method, double ransacReprojThreshold ) : HomographyMatrix
srcPoints Matrix Point coordinates in the original plane, 2xN, Nx2, 3xN or Nx3 array (the latter two are for representation in homogeneous coordinates), where N is the number of points
dstPoints Matrix Point coordinates in the destination plane, 2xN, Nx2, 3xN or Nx3 array (the latter two are for representation in homogeneous coordinates)
method CvEnum FindHomography method
ransacReprojThreshold double The maximum allowed reprojection error to treat a point pair as an inlier. The parameter is only used in RANSAC-based homography estimation. E.g. if dst_points coordinates are measured in pixels with pixel-accurate precision, it makes sense to set this parameter somewhere in the range ~1..3
Результат HomographyMatrix
Пример #1
0
        /// <summary>
        /// Recover the homography matrix using RANDSAC. If the matrix cannot be recovered, null is returned.
        /// </summary>
        /// <param name="matchedFeatures">The Matched Features, only the first ModelFeature will be considered</param>
        /// <returns>The homography matrix, if it cannot be found, null is returned</returns>
        public static HomographyMatrix GetHomographyMatrixFromMatchedFeatures(MatchedSURFFeature[] matchedFeatures)
        {
            if (matchedFeatures.Length < 4)
            {
                return(null);
            }

            HomographyMatrix homography;

            if (matchedFeatures.Length < _randsacRequiredMatch)
            { // Too few points for randsac, use 4 points only
                PointF[] pts1 = new PointF[4];
                PointF[] pts2 = new PointF[4];
                for (int i = 0; i < 4; i++)
                {
                    pts1[i] = matchedFeatures[i].SimilarFeatures[0].Feature.Point.pt;
                    pts2[i] = matchedFeatures[i].ObservedFeature.Point.pt;
                }
                homography = CameraCalibration.GetPerspectiveTransform(pts1, pts2);
            }
            else
            {
                //use randsac to find the Homography Matrix
                PointF[] pts1 = new PointF[matchedFeatures.Length];
                PointF[] pts2 = new PointF[matchedFeatures.Length];
                for (int i = 0; i < matchedFeatures.Length; i++)
                {
                    pts1[i] = matchedFeatures[i].SimilarFeatures[0].Feature.Point.pt;
                    pts2[i] = matchedFeatures[i].ObservedFeature.Point.pt;
                }

                homography = CameraCalibration.FindHomography(
                    pts1, //points on the model image
                    pts2, //points on the observed image
                    CvEnum.HOMOGRAPHY_METHOD.RANSAC,
                    3);
                if (homography == null)
                {
                    return(null);
                }
            }

            if (homography.IsValid(10))
            {
                return(homography);
            }
            else
            {
                homography.Dispose();
                return(null);
            }
        }