Example #1
0
        public void PointTransformAffineCreateException()
        {
            PointTransformAffine transform = null;
            DPoint          vector;
            Matrix <double> matrix = null;

            try
            {
                matrix    = new Matrix <double>();
                vector    = new DPoint();
                transform = new PointTransformAffine(matrix, vector);
                Assert.True(false, "PointTransformAffine should not accept not 2x2 matrix");
            }
            catch
            {
                Console.WriteLine("OK");
            }
            finally
            {
                if (matrix != null)
                {
                    this.DisposeAndCheckDisposedState(matrix);
                }
                if (transform != null)
                {
                    this.DisposeAndCheckDisposedState(transform);
                }
            }
        }
Example #2
0
        public void RectangleTransformCreate1()
        {
            var pointTransformAffine = new PointTransformAffine();
            var transform            = new RectangleTransform(pointTransformAffine);

            this.DisposeAndCheckDisposedState(pointTransformAffine);
            this.DisposeAndCheckDisposedState(transform);
        }
Example #3
0
 public void PointTransformAffineCreate1()
 {
     for (var x = -10d; x <= 10d; x += 0.5)
     {
         for (var y = -10d; y <= 10d; y += 0.5)
         {
             var matrix    = new Matrix <double>(2, 2);
             var vector    = new DPoint(x, y);
             var transform = new PointTransformAffine(matrix, vector);
             this.DisposeAndCheckDisposedState(matrix);
             this.DisposeAndCheckDisposedState(transform);
         }
     }
 }
Example #4
0
 public void PointTransformAffineB()
 {
     for (var x = -10d; x <= 10d; x += 0.5)
     {
         for (var y = -10d; y <= 10d; y += 0.5)
         {
             var matrix    = new Matrix <double>(2, 2);
             var vector    = new DPoint(x, y);
             var transform = new PointTransformAffine(matrix, vector);
             var b         = transform.B;
             Assert.Equal(b.X, x);
             Assert.Equal(b.Y, y);
             this.DisposeAndCheckDisposedState(transform);
             this.DisposeAndCheckDisposedState(matrix);
         }
     }
 }
Example #5
0
 public void PointTransformAffineM()
 {
     for (var x = -10d; x <= 10d; x += 0.5)
     {
         for (var y = -10d; y <= 10d; y += 0.5)
         {
             var matrix    = new Matrix <double>(2, 2);
             var vector    = new DPoint(x, y);
             var transform = new PointTransformAffine(matrix, vector);
             var m         = transform.M;
             Assert.Equal(m.MatrixElementType, MatrixElementTypes.Double);
             Assert.Equal(m.Rows, 2);
             Assert.Equal(m.Columns, 2);
             this.DisposeAndCheckDisposedState(m);
             this.DisposeAndCheckDisposedState(transform);
             this.DisposeAndCheckDisposedState(matrix);
         }
     }
 }
Example #6
0
 public void PointTransformAffineOperator()
 {
     for (var x = -10d; x <= 10d; x += 0.5)
     {
         for (var y = -10d; y <= 10d; y += 0.5)
         {
             var matrix    = new Matrix <double>(2, 2);
             var vector    = new DPoint(x, y);
             var transform = new PointTransformAffine(matrix, vector);
             var vector2   = new DPoint(x * 2, y * 2);
             var ret       = transform.Operator(vector2);
             this.DisposeAndCheckDisposedState(ret);
             this.DisposeAndCheckDisposedState(vector2);
             this.DisposeAndCheckDisposedState(transform);
             this.DisposeAndCheckDisposedState(vector);
             this.DisposeAndCheckDisposedState(matrix);
         }
     }
 }
Example #7
0
        public void TransformImagePointTransformAffine()
        {
            const string testName = "TransformImagePointTransformAffine";
            var          path     = this.GetDataFile($"{LoadTarget}.bmp");

            var tests = new[]
            {
                new { Type = ImageTypes.HsiPixel, ExpectResult = false },
                new { Type = ImageTypes.RgbAlphaPixel, ExpectResult = false },
                new { Type = ImageTypes.RgbPixel, ExpectResult = true },
                new { Type = ImageTypes.UInt8, ExpectResult = true },
                new { Type = ImageTypes.UInt16, ExpectResult = true },
                new { Type = ImageTypes.Float, ExpectResult = true },
                new { Type = ImageTypes.Double, ExpectResult = true }
            };

            var angleCases = new[]
            {
                //45d, -45d, 90d, 180d
                0d
            };

            var xCases = new[]
            {
                //10, -10, 50,5, -50,5
                0d
            };

            var yCases = new[]
            {
                //10, -10, 50,5, -50,5
                0d
            };

            var type = this.GetType().Name;

            foreach (var angle in angleCases)
            {
                foreach (var x in xCases)
                {
                    foreach (var y in yCases)
                    {
                        foreach (var input in tests)
                        {
                            foreach (var output in tests)
                            {
                                var expectResult = input.ExpectResult && output.ExpectResult;
                                var imageObj     = DlibTest.LoadImage(input.Type, path);
                                var outputObj    = Array2DTest.CreateArray2D(output.Type, imageObj.Rows, imageObj.Columns);
                                var matrix       = new Matrix <double>(2, 2);
                                //var rad = Math.PI / (180d / angle);
                                //matrix.Assign(new[] { Math.Cos(rad), -Math.Sin(rad), Math.Sin(rad), Math.Cos(rad) });
                                var transform = new PointTransformAffine(matrix, x, y);

                                var outputImageAction = new Func <bool, Array2DBase>(expect =>
                                {
                                    Dlib.TransformImage(imageObj, outputObj, transform);
                                    return(outputObj);
                                });

                                var successAction = new Action <Array2DBase>(image =>
                                {
                                    Dlib.SaveJpeg(image, $"{Path.Combine(this.GetOutDir(type, testName), $"{LoadTarget}_{input.Type}_{output.Type}_{angle}_{x}_{y}.jpg")}");
                                });

                                var failAction = new Action(() =>
                                {
                                    Assert.Fail($"{testName} should throw excption for InputType: {input.Type}, OutputType: {output.Type}, Angle,: {angle}, X: {x}, Y: {y}.");
                                });

                                var finallyAction = new Action(() =>
                                {
                                    this.DisposeAndCheckDisposedState(matrix);
                                    this.DisposeAndCheckDisposedState(transform);
                                    this.DisposeAndCheckDisposedState(imageObj);
                                    if (outputObj != null)
                                    {
                                        this.DisposeAndCheckDisposedState(outputObj);
                                    }
                                });

                                var exceptionAction = new Action(() =>
                                {
                                    Console.WriteLine($"Failed to execute {testName} to InputType: {input.Type}, OutputType: {output.Type}, Angle,: {angle}, X: {x}, Y: {y}.");
                                });

                                DoTest(outputImageAction, expectResult, successAction, finallyAction, failAction, exceptionAction);
                            }
                        }
                    }
                }
            }
        }
Example #8
0
        public void PointTransformAffineCreate()
        {
            var transform = new PointTransformAffine();

            this.DisposeAndCheckDisposedState(transform);
        }
Example #9
0
        public void PointTransformAffineCreateException()
        {
            PointTransformAffine transform = null;
            DPoint          vector         = null;
            Matrix <double> matrix         = null;

            try
            {
                vector    = new DPoint();
                transform = new PointTransformAffine(null, vector);
                Assert.Fail("PointTransformAffine should not accept null object for 1st argument");
            }
            catch
            {
                Console.WriteLine("OK");
            }
            finally
            {
                if (vector != null)
                {
                    this.DisposeAndCheckDisposedState(vector);
                }
                if (transform != null)
                {
                    this.DisposeAndCheckDisposedState(transform);
                }
            }

            try
            {
                matrix    = new Matrix <double>(2, 2);
                transform = new PointTransformAffine(matrix, null);
                Assert.Fail("PointTransformAffine should not accept null object for 2nd argument");
            }
            catch
            {
                Console.WriteLine("OK");
            }
            finally
            {
                if (matrix != null)
                {
                    this.DisposeAndCheckDisposedState(matrix);
                }
                if (vector != null)
                {
                    this.DisposeAndCheckDisposedState(vector);
                }
                if (transform != null)
                {
                    this.DisposeAndCheckDisposedState(transform);
                }
            }

            try
            {
                matrix    = new Matrix <double>();
                vector    = new DPoint();
                transform = new PointTransformAffine(matrix, vector);
                Assert.Fail("PointTransformAffine should not accept not 2x2 matrix");
            }
            catch
            {
                Console.WriteLine("OK");
            }
            finally
            {
                if (matrix != null)
                {
                    this.DisposeAndCheckDisposedState(matrix);
                }
                if (vector != null)
                {
                    this.DisposeAndCheckDisposedState(vector);
                }
                if (transform != null)
                {
                    this.DisposeAndCheckDisposedState(transform);
                }
            }
        }