public static extern int cvFindHomography( IntPtr srcPoints, IntPtr dstPoints, IntPtr homography, CvEnum.HOMOGRAPHY_METHOD method, double ransacReprojThreshold, IntPtr mask);
/// <summary> /// Use the specific method to find perspective transformation H=||h_ij|| between the source and the destination planes /// </summary> /// <param name="srcPoints">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</param> /// <param name="dstPoints">Point coordinates in the destination plane, 2xN, Nx2, 3xN or Nx3 array (the latter two are for representation in homogeneous coordinates) </param> /// <param name="method">FindHomography method</param> /// <param name="ransacReprojThreshold">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</param> /// <returns>The 3x3 homography matrix if found. Null if not found.</returns> public static HomographyMatrix FindHomography( Matrix <float> srcPoints, Matrix <float> dstPoints, CvEnum.HOMOGRAPHY_METHOD method, double ransacReprojThreshold) { HomographyMatrix homography = new HomographyMatrix(); if (!CvInvoke.cvFindHomography(srcPoints.Ptr, dstPoints.Ptr, homography.Ptr, method, ransacReprojThreshold, IntPtr.Zero)) { homography.Dispose(); return(null); } return(homography); }
/// <summary> /// Finds perspective transformation H=||h_ij|| between the source and the destination planes /// </summary> /// <param name="srcPoints">Point coordinates in the original plane</param> /// <param name="dstPoints">Point coordinates in the destination plane</param> /// <param name="method">FindHomography method</param> /// <param name="ransacReprojThreshold"> /// 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 /// </param> /// <returns>The 3x3 homography matrix if found. Null if not found.</returns> public static HomographyMatrix FindHomography( PointF[] srcPoints, PointF[] dstPoints, CvEnum.HOMOGRAPHY_METHOD method, double ransacReprojThreshold) { HomographyMatrix homography; GCHandle srcHandle = GCHandle.Alloc(srcPoints, GCHandleType.Pinned); GCHandle dstHandle = GCHandle.Alloc(dstPoints, GCHandleType.Pinned); using (Matrix <float> srcPointMatrix = new Matrix <float>(srcPoints.Length, 2, srcHandle.AddrOfPinnedObject())) using (Matrix <float> dstPointMatrix = new Matrix <float>(dstPoints.Length, 2, dstHandle.AddrOfPinnedObject())) homography = FindHomography(srcPointMatrix, dstPointMatrix, method, ransacReprojThreshold); srcHandle.Free(); dstHandle.Free(); return(homography); }