Accord.MachineLearning.Geometry.RansacPlane.Estimate C# (CSharp) Метод

Estimate() публичный Метод

Produces a robust estimation of the plane passing through the given (noisy) points.
public Estimate ( Point3 points ) : Plane
points Accord.Math.Point3 A set of (possibly noisy) points.
Результат Plane
        public Plane Estimate(Point3[] points)
        {
            // Initial argument checks
            if (points.Length < 3)
                throw new ArgumentException("At least three points are required to fit a plane");

            this.d2 = new double[points.Length];
            this.points = points;

            // Compute RANSAC and find the inlier points
            ransac.Compute(points.Length, out inliers);

            if (inliers.Length == 0)
                return null;

            // Compute the final plane
            Plane plane = fitting(points.Get(inliers));

            return plane;
        }

Usage Example

Пример #1
0
        public void RansacPlaneConstructorTest()
        {
            Accord.Math.Tools.SetupGenerator(0);

            {
                Point3[] points = new Point3[300];

                int c = 0;
                for (int i = 0; i < points.Length / 3; i++)
                {
                    points[c++] = new Point3((float)i, (float)0, (float)0);
                    points[c++] = new Point3((float)0, (float)i, (float)0);
                    points[c++] = new Point3((float)i, (float)i, (float)0);
                }

                RansacPlane target = new RansacPlane(0.80, 0.9);

                Plane expected = Plane.FromPoints(points[3], points[4], points[5]);
                Plane actual = target.Estimate(points);

                Assert.AreEqual(actual.A, 0);
                Assert.AreEqual(actual.B, 0);
                Assert.AreEqual(actual.C, -1);
                Assert.AreEqual(actual.Offset, 0);

                Assert.IsTrue(expected.Equals(actual, 1e-3));
            }

            {
                Point3[] points = new Point3[300];

                int c = 0;
                for (int i = 0; i < points.Length / 3; i++)
                {
                    points[c++] = new Point3((float)i, (float)0, (float)50);
                    points[c++] = new Point3((float)0, (float)i, (float)50);
                    points[c++] = new Point3((float)i, (float)i, (float)50);
                }

                RansacPlane target = new RansacPlane(0.80, 0.9);

                Plane expected = Plane.FromPoints(points[6], points[7], points[8]);
                expected.Normalize();

                Plane actual = target.Estimate(points);

                Assert.AreEqual(actual.A, 0);
                Assert.AreEqual(actual.B, 0, 1e-5);
                Assert.AreEqual(actual.C, -1, 1e-5);
                Assert.AreEqual(actual.Offset, 50, 1e-4);

                Assert.IsTrue(expected.Equals(actual, 1e-3));
            }

            {
                Point3[] points = new Point3[10 * 10];

                int c = 0;
                for (int i = 0; i < 10; i++)
                {
                    for (int j = 0; j < 10; j++)
                    {
                        double x = i + 5 * Accord.Math.Tools.Random.NextDouble();
                        double y = j + 5 * Accord.Math.Tools.Random.NextDouble();
                        double z = x + y - 1;

                        points[c++] = new Point3((float)x, (float)z, (float)y);
                    }
                }

                RansacPlane target = new RansacPlane(0.80, 0.9);

                Plane actual = target.Estimate(points);
                var normal = actual.Normal / actual.Normal.Max;

                Assert.AreEqual(normal.X, +1, 1e-5);
                Assert.AreEqual(normal.Y, -1, 1e-5);
                Assert.AreEqual(normal.Z, +1, 1e-5);
            }
        }
All Usage Examples Of Accord.MachineLearning.Geometry.RansacPlane::Estimate