示例#1
0
        /// <summary>
        ///   Matches two sets of points using RANSAC.
        /// </summary>
        ///
        /// <returns>The fundamental matrix relating x1 and x2.</returns>
        ///
        public float[,] Estimate(PointF[] points1, PointF[] points2)
        {
            // Initial argument checks
            if (points1.Length != points2.Length)
            {
                throw new ArgumentException("The number of points should be equal.");
            }

            if (points1.Length < 8)
            {
                throw new ArgumentException("At least eight points are required.");
            }


            // Normalize each set of points so that the origin is
            //  at centroid and mean distance from origin is sqrt(2).
            float[,] T1, T2;
            this.pointSet1 = Tools.Normalize(points1, out T1);
            this.pointSet2 = Tools.Normalize(points2, out T2);


            // Compute RANSAC and find the inlier points
            float[,] F = ransac.Compute(points1.Length, out inliers);

            if (inliers == null || inliers.Length < 8)
            {
                return(null);
            }

            // Compute the final fundamental
            // matrix considering all inliers
            F = fundamental(inliers);

            // Denormalize
            F = T2.TransposeAndDot(F.Dot(T1));

            return(F);
        }