Homography() public static méthode

Creates an homography matrix matching points from a set of points to another.
public static Homography ( PointF points1, PointF points2 ) : MatrixH
points1 System.Drawing.PointF
points2 System.Drawing.PointF
Résultat MatrixH
Exemple #1
0
        /// <summary>
        ///   Estimates a homography with the given points.
        /// </summary>
        ///
        private MatrixH homography(int[] points)
        {
            // Retrieve the original points
            PointF[] x1 = this.pointSet1.Submatrix(points);
            PointF[] x2 = this.pointSet2.Submatrix(points);

            // Compute the homography
            return(Tools.Homography(x1, x2));
        }
        public void HomographyTestF()
        {
            PointF[] x1 =
            {
                new PointF(0, 0),
                new PointF(1, 0),
                new PointF(0, 1),
                new PointF(1, 1),
            };

            PointF[] x2 =
            {
                new PointF(0, 0),
                new PointF(1, 0),
                new PointF(0, 1),
                new PointF(1, 1),
            };

            float[,] expected = Matrix.Identity(3).ToSingle();

            float[,] actual = (float[, ])Tools.Homography(x1, x2);

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    actual[i, j] /= actual[2, 2];
                }
            }


            Assert.IsTrue(Matrix.IsEqual(expected, actual, 1e-5f));


            x1 = new PointF[]
            {
                new PointF(2, 0),
                new PointF(1, 0),
                new PointF(5, 1),
                new PointF(1, 1),
                new PointF(7, 1),
                new PointF(1, 2),
                new PointF(1, 1),
            };

            x2 = new PointF[]
            {
                new PointF(9, 1),
                new PointF(1, 5),
                new PointF(9, 1),
                new PointF(1, 7),
                new PointF(2, 7),
                new PointF(6, 5),
                new PointF(1, 7),
            };

            expected = new float[, ]
            {
                { 0.2225f, -3.1727f, 1.8023f },
                { 0.3648f, -1.7149f, -0.2173f },
                { 0.0607f, -0.4562f, 0.1229f },
            };

            expected = (float[, ])(new MatrixH(expected));

            actual = (float[, ])Tools.Homography(x1, x2);

            Assert.IsTrue(Matrix.IsEqual(expected, actual, 0.01f));
        }
        public void HomographyTest()
        {
            PointH[] x1 =
            {
                new PointH(0, 0),
                new PointH(1, 0),
                new PointH(0, 1),
                new PointH(1, 1),
            };

            PointH[] x2 =
            {
                new PointH(0, 0),
                new PointH(1, 0),
                new PointH(0, 1),
                new PointH(1, 1),
            };

            double[,] expected = Matrix.Identity(3);

            double[,] actual = (double[, ])Tools.Homography(x1, x2);

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    actual[i, j] /= actual[2, 2];
                }
            }

            Assert.IsTrue(Matrix.IsEqual(expected, actual, 1e-4));


            x1 = new PointH[]
            {
                new PointH(2, 0),
                new PointH(1, 0),
                new PointH(5, 1),
                new PointH(1, 1),
                new PointH(7, 1),
                new PointH(1, 2),
                new PointH(1, 1),
            };

            x2 = new PointH[]
            {
                new PointH(9, 1),
                new PointH(1, 5),
                new PointH(9, 1),
                new PointH(1, 7),
                new PointH(2, 7),
                new PointH(6, 5),
                new PointH(1, 7),
            };

            expected = new double[, ]
            {
                { 0.2225, -3.1727, 1.8023 },
                { 0.3648, -1.7149, -0.2173 },
                { 0.0607, -0.4562, 0.1229 },
            };

            expected = (double[, ])(new MatrixH(expected));

            actual = (double[, ])Tools.Homography(x1, x2);

            Assert.IsTrue(Matrix.IsEqual(expected, actual, 0.01));
        }