public void TestWithNoPreset()
        {
            var            test      = new TestDescription(MethodBase.GetCurrentMethod().Name, this.GetType().Name);
            ImageGenerator generator = new ImageGenerator(test.Name);
            var            img       = generator.RenderImage();

            TestImageHelper.SaveBitmap(test.FileName_Image, img);

            Sink.ResetPoints();
            var sut     = new MarkerScanner(Sink.PromptNewMessage_Handler, Sink.OnAnchorSetEvent, Sink.OnMovingTipSetEvent);
            var profile = new TargetProfile()
            {
                Centre = new BlobCentre()
                {
                    X = 300, Y = 300
                }, Color = System.Drawing.Color.FromArgb(255, 255, 255)
            };

            Sink.MyLog.Clear();
            var pImg = sut.ProcessImage(img, 3);

            TestImageHelper.SaveBitmap(test.FileName_Processed, pImg as BitmapSource);

            Assert.IsTrue(Sink.MyLog.Count == 1);
            Assert.IsTrue(Sink.MyLog[0].Contains("Anchor point not found. Please specify Anchor point first"));

            Assert.AreEqual(null, sut.Profile);
        }
Exemple #2
0
        public void TestWithNoBlob()
        {
            var            test      = new TestDescription(MethodBase.GetCurrentMethod().Name, this.GetType().Name);
            ImageGenerator generator = new ImageGenerator(test.Name);
            var            img       = generator.RenderImage();

            TestImageHelper.SaveBitmap(test.FileName_Image, img);

            Sink.ResetPoints();
            var sut     = new MarkerScanner(Sink.PromptNewMessage_Handler, Sink.OnAnchorSetEvent, Sink.OnMovingTipSetEvent);
            var profile = new TargetProfile()
            {
                Centre = new BlobCentre()
                {
                    X = 300, Y = 300
                }, Color = System.Drawing.Color.FromArgb(255, 255, 255)
            };

            Sink.MyLog.Clear();
            var pImg = sut.TryToSetAnchor(img, profile);

            TestImageHelper.SaveBitmap(test.FileName_Processed, pImg as BitmapSource);

            Assert.IsTrue(Sink.MyLog.Count > 2);
            Assert.IsTrue(Sink.MyLog[Sink.MyLog.Count - 2].Contains("Unable to find reference point with size"));
            Assert.IsTrue(Sink.MyLog[Sink.MyLog.Count - 1].Contains("No suitable marker for Anchor point not found"));

            Assert.AreEqual(null, sut.Profile);
        }
        public void TestWithCorrectPreset()
        {
            var            test      = new TestDescription(MethodBase.GetCurrentMethod().Name, this.GetType().Name);
            ImageGenerator generator = new ImageGenerator(test.Name);
            Marker         vAncor    = new Marker()
            {
                Center   = ImageGenerator.DefaultCentre,
                Diameter = 60,
                Fill     = Colors.Green,
                Border   = Colors.Gray
            };

            generator.AddMarkerToImage(vAncor);

            Marker vTip = new Marker()
            {
                Center   = ImageGenerator.DefaultCentre + new Vector(0, ImageGenerator.DefaultRadius),
                Diameter = 100,
                Fill     = Colors.Blue,
                Border   = Colors.Gray
            };

            generator.AddMarkerToImage(vTip);

            var img = generator.RenderImage();

            TestImageHelper.SaveBitmap(test.FileName_Image, img);

            var sut      = new MarkerScanner(Sink.PromptNewMessage_Handler, Sink.OnAnchorSetEvent, Sink.OnMovingTipSetEvent);
            var aProfile = new TargetProfile()
            {
                Centre = new BlobCentre(vAncor.Center, 0), Color = Extensions.SetColor(vAncor.Fill)
            };
            var mtProfile = new TargetProfile()
            {
                Centre = new BlobCentre(vTip.Center, 0), Color = Extensions.SetColor(vTip.Fill)
            };

            Sink.MyLog.Clear();
            Sink.ResetPoints();
            sut.TryToSetAnchor(img, aProfile);
            sut.TryToSetTip(img, mtProfile);

            var pImg = sut.ProcessImage(img, 1);

            TestImageHelper.SaveBitmap(test.FileName_Processed, pImg as BitmapSource);

            Assert.AreEqual(vAncor.Center.X, Sink.Anchor.C.X, 2);
            Assert.AreEqual(vAncor.Center.Y, Sink.Anchor.C.Y, 2);
            Assert.AreEqual(vAncor.Diameter, Sink.Anchor.D, 2);

            Assert.AreEqual(aProfile.Centre.X, sut.Profile.Anchor.Initial.Centre.X);
            Assert.AreEqual(aProfile.Centre.Y, sut.Profile.Anchor.Initial.Centre.Y);
            Assert.AreEqual(aProfile.Centre.D, sut.Profile.Anchor.Initial.Centre.D);

            Assert.AreEqual(vTip.Center.X, Sink.MovingTip.C.X, 2);
            Assert.AreEqual(vTip.Center.Y, Sink.MovingTip.C.Y, 2);
            Assert.AreEqual(vTip.Diameter, Sink.MovingTip.D, 2);
        }
Exemple #4
0
        public void TestWithTwoBlobAndOtherCorrectPosition()
        {
            var            test      = new TestDescription(MethodBase.GetCurrentMethod().Name, this.GetType().Name);
            ImageGenerator generator = new ImageGenerator(test.Name);
            Marker         vAncor    = new Marker()
            {
                Center   = new Point(300, 400),
                Diameter = 60,
                Fill     = Colors.Green,
                Border   = Colors.Gray
            };

            generator.AddMarkerToImage(vAncor);

            Marker vTip = new Marker()
            {
                Center   = new Point(900, 800),
                Diameter = 100,
                Fill     = Colors.Green,
                Border   = Colors.Gray
            };

            generator.AddMarkerToImage(vTip);

            var img = generator.RenderImage();

            TestImageHelper.SaveBitmap(test.FileName_Image, img);

            Sink.ResetPoints();
            var sut     = new MarkerScanner(Sink.PromptNewMessage_Handler, Sink.OnAnchorSetEvent, Sink.OnMovingTipSetEvent);
            var profile = new TargetProfile()
            {
                Centre = new BlobCentre()
                {
                    X = 900, Y = 800
                }, Color = Extensions.SetColor(vAncor.Fill)
            };

            Sink.MyLog.Clear();
            var pImg = sut.TryToSetAnchor(img, profile);

            TestImageHelper.SaveBitmap(test.FileName_Processed, pImg as BitmapSource);

            Assert.IsTrue(Sink.MyLog[Sink.MyLog.Count - 1].Contains("Anchor point set - Remaining dot preset as moving tip"));
            Assert.AreEqual(900, Sink.Anchor.C.X, 2);
            Assert.AreEqual(800, Sink.Anchor.C.Y, 2);
            Assert.AreEqual(100, Sink.Anchor.D, 2);

            Assert.AreEqual(profile.Centre.X, sut.Profile.Anchor.Initial.Centre.X);
            Assert.AreEqual(profile.Centre.Y, sut.Profile.Anchor.Initial.Centre.Y);
            Assert.AreEqual(profile.Centre.D, sut.Profile.Anchor.Initial.Centre.D);

            Assert.AreEqual(300, Sink.MovingTip.C.X, 2);
            Assert.AreEqual(400, Sink.MovingTip.C.Y, 2);
            Assert.AreEqual(60, Sink.MovingTip.D, 2);
        }
Exemple #5
0
        public void TestWithOneBlobAndCorrectPositionButWrongColor()
        {
            var            test      = new TestDescription(MethodBase.GetCurrentMethod().Name, this.GetType().Name);
            ImageGenerator generator = new ImageGenerator(test.Name);
            Marker         vAncor    = new Marker()
            {
                Center   = new Point(300, 300),
                Diameter = 60,
                Fill     = Colors.Green,
                Border   = Colors.Gray
            };

            generator.AddMarkerToImage(vAncor);
            var img = generator.RenderImage();

            TestImageHelper.SaveBitmap(test.FileName_Image, img);

            Sink.ResetPoints();
            var sut     = new MarkerScanner(Sink.PromptNewMessage_Handler, Sink.OnAnchorSetEvent, Sink.OnMovingTipSetEvent);
            var profile = new TargetProfile()
            {
                Centre = new BlobCentre()
                {
                    X = 300, Y = 300
                }, Color = Extensions.SetColor(Colors.Blue)
            };

            Sink.MyLog.Clear();
            var pImg = sut.TryToSetAnchor(img, profile);

            TestImageHelper.SaveBitmap(test.FileName_Processed, pImg as BitmapSource);

            Assert.IsTrue(Sink.MyLog.Count >= 1);
            Assert.IsTrue(Sink.MyLog[Sink.MyLog.Count - 1].Contains("No suitable marker for Anchor point not found"));

            Assert.AreEqual(null, sut.Profile);
        }
        public void TestWithNoTipPreset()
        {
            var            test      = new TestDescription(MethodBase.GetCurrentMethod().Name, this.GetType().Name);
            ImageGenerator generator = new ImageGenerator(test.Name);
            Marker         vAncor    = new Marker()
            {
                Center   = new Point(300, 300),
                Diameter = 60,
                Fill     = Colors.Green,
                Border   = Colors.Gray
            };

            generator.AddMarkerToImage(vAncor);
            var img = generator.RenderImage();

            TestImageHelper.SaveBitmap(test.FileName_Image, img);

            Sink.ResetPoints();
            var sut     = new MarkerScanner(Sink.PromptNewMessage_Handler, Sink.OnAnchorSetEvent, Sink.OnMovingTipSetEvent);
            var profile = new TargetProfile()
            {
                Centre = new BlobCentre()
                {
                    X = 300, Y = 300
                }, Color = Extensions.SetColor(vAncor.Fill)
            };

            sut.TryToSetAnchor(img, profile);
            Sink.MyLog.Clear();
            var pImg = sut.ProcessImage(img, 3);

            TestImageHelper.SaveBitmap(test.FileName_Processed, pImg as BitmapSource);

            Assert.IsTrue(Sink.MyLog.Count == 1);
            Assert.IsTrue(Sink.MyLog[0].Contains("Moving point not found. Please specify Moving point first"));
        }
        public void TestWithMovingMarkers()
        {
            double dPhi = 4;
            double Phi  = 40;

            double phi = 0;

            string name = Path.Combine(this.GetType().Name, $"Moving");

            do
            {
                var            test      = new TestDescription(MethodBase.GetCurrentMethod().Name, name);
                ImageGenerator generator = new ImageGenerator(test.Name);
                Marker         vAncor    = new Marker()
                {
                    Center   = ImageGenerator.DefaultCentre,
                    Diameter = 60,
                    Fill     = Colors.Green,
                    Border   = Colors.Gray
                };
                generator.AddMarkerToImage(vAncor);

                var    xDelta = ImageGenerator.DefaultRadius * Math.Sin(Extensions.ConvertToRadians(phi));
                var    yDelta = ImageGenerator.DefaultRadius * Math.Cos(Extensions.ConvertToRadians(phi));
                var    delta  = new Vector(xDelta, yDelta);
                Marker vTip   = new Marker()
                {
                    Center   = ImageGenerator.DefaultCentre + delta,
                    Diameter = 100,
                    Fill     = Colors.Blue,
                    Border   = Colors.Gray
                };
                generator.AddMarkerToImage(vTip);

                var img = generator.RenderImage();
                TestImageHelper.SaveBitmap(test.FileName_Image, img);

                var sut      = new MarkerScanner(Sink.PromptNewMessage_Handler, Sink.OnAnchorSetEvent, Sink.OnMovingTipSetEvent);
                var aProfile = new TargetProfile()
                {
                    Centre = new BlobCentre(vAncor.Center, 0), Color = Extensions.SetColor(vAncor.Fill)
                };
                var mtProfile = new TargetProfile()
                {
                    Centre = new BlobCentre(vTip.Center, 0), Color = Extensions.SetColor(vTip.Fill)
                };

                Sink.MyLog.Clear();
                Sink.ResetPoints();
                sut.TryToSetAnchor(img, aProfile);
                sut.TryToSetTip(img, mtProfile);

                var pImg = sut.ProcessImage(img, 1);

                TestImageHelper.SaveBitmap(test.FileName_Processed, pImg as BitmapSource);

                Assert.AreEqual(vAncor.Center.X, Sink.Anchor.C.X, 2);
                Assert.AreEqual(vAncor.Center.Y, Sink.Anchor.C.Y, 2);
                Assert.AreEqual(vAncor.Diameter, Sink.Anchor.D, 2);

                Assert.AreEqual(aProfile.Centre.X, sut.Profile.Anchor.Initial.Centre.X);
                Assert.AreEqual(aProfile.Centre.Y, sut.Profile.Anchor.Initial.Centre.Y);
                Assert.AreEqual(aProfile.Centre.D, sut.Profile.Anchor.Initial.Centre.D);

                Assert.AreEqual(vTip.Center.X, Sink.MovingTip.C.X, 2);
                Assert.AreEqual(vTip.Center.Y, Sink.MovingTip.C.Y, 2);
                Assert.AreEqual(vTip.Diameter, Sink.MovingTip.D, 2);

                phi = phi + dPhi;
            } while (phi <= Phi);
        }