public void TestEdgePtProcessors()
        {
            var backgroundColor = TestHelper.GetBackgroundColor();
            var image           = TestHelper.GetStrippedFirstMarioImage(backgroundColor);

            var leftEdgeProcessor  = new LeftEdgePtsProcessor(image, backgroundColor);
            var rightEdgeProcessor = new RightEdgePtsProcessor(image, backgroundColor);

            var leftMarkingColor  = Color.DarkViolet;
            var rightMarkingColor = Color.Gold;

            for (var y = 0; y < image.Height; y++)
            {
                try
                {
                    var leftPt = leftEdgeProcessor.GetEdgePt(y);
                    image.SetPixel(leftPt.X, y, leftMarkingColor);
                }
                catch {}

                try
                {
                    var rightPt = rightEdgeProcessor.GetEdgePt(y);
                    image.SetPixel(rightPt.X, y, rightMarkingColor);
                }
                catch {}
            }

            image.Save(ExecutionDirInfoHelper.GetOutputDirPath() + @"\TestEdgePtProcessors.bmp");
        }
Example #2
0
        private static void SaveResults(Image bitmap, string outputFileName)
        {
            var outputPath     = ExecutionDirInfoHelper.GetOutputDirPath();
            var outputFilePath = string.Format(@"{0}\HolePluggerTests_{1}.png", outputPath, outputFileName);

            bitmap.Save(outputFilePath);
        }
Example #3
0
        public void TestLinePtProcessorsForPerfectlyVerticalBase()
        {
            var          backgroundColor         = TestHelper.GetBackgroundColor();
            var          image                   = TestHelper.GetStrippedTestImageForPerfectlyVerticalBase(backgroundColor);
            const string testlineptprocessorsBmp = @"\TestLinePtProcessorsForPerfectlyVerticalBase.bmp";

            ProcessLineValues(backgroundColor, image, 100);

            image.Save(ExecutionDirInfoHelper.GetOutputDirPath() + testlineptprocessorsBmp);
        }
Example #4
0
        public void TestLinePtProcessorsForMarioImage()
        {
            var          backgroundColor         = TestHelper.GetBackgroundColor();
            var          image                   = TestHelper.GetStrippedFirstMarioImage(backgroundColor);
            const string testlineptprocessorsBmp = @"\TestLinePtProcessorsForMarioImage.bmp";

            ProcessLineValues(backgroundColor, image, 25);

            image.Save(ExecutionDirInfoHelper.GetOutputDirPath() + testlineptprocessorsBmp);
        }
        public void TestColorVariationPercentBasedStripperWithMyPhotoImage()
        {
            const string inputFileName  = @"\MyPhoto.jpg";
            const string outputFileName = @"\TestColorVariationPercentBasedStripperWithMyPhotoImage.png";

            var sourceImagePath = ExecutionDirInfoHelper.GetInputDirPath() + inputFileName;
            var bitmap          = (Bitmap)Image.FromFile(sourceImagePath);
            var backgroundColor = new SerializableColor(200, 200, 200);

            var @params = new BackgroundStrippingParams
            {
                BackgroundColor           = backgroundColor,
                ColorVariationBasedParams = new ColorVariationBasedParams
                {
                    VariationPercent = 10,
                    CompareColor     = GetColor(bitmap.GetPixel(0, 0))
                }
            };

            BackgroundStripper.StripBackground(bitmap, @params);

            var @params1 = new BackgroundStrippingParams
            {
                BackgroundColor           = backgroundColor,
                ColorVariationBasedParams = new ColorVariationBasedParams
                {
                    VariationPercent = 5,
                    CompareColor     = GetColor(bitmap.GetPixel(626, 1802))
                }
            };

            BackgroundStripper.StripBackground(bitmap, @params1);

            var @params2 = new BackgroundStrippingParams
            {
                BackgroundColor           = backgroundColor,
                ColorVariationBasedParams = new ColorVariationBasedParams
                {
                    VariationPercent = 5,
                    CompareColor     = GetColor(bitmap.GetPixel(549, 1750))
                }
            };

            BackgroundStripper.StripBackground(bitmap, @params2);

            var targetPath = ExecutionDirInfoHelper.GetOutputDirPath() + outputFileName;

            bitmap.Save(targetPath);
        }
        private static void PrintProvidedVariations(Image image, int targetYVal, IEnumerable <double> variations, string outputFile)
        {
            var g = Graphics.FromImage(image);
            var x = 0;

            foreach (var variation in variations)
            {
                var y = variation * 300;
                g.DrawLine(Pens.Red, x, image.Height - targetYVal, x, image.Height - targetYVal - (int)y);
                x++;
            }
            g.Dispose();

            image.Save(ExecutionDirInfoHelper.GetOutputDirPath() + outputFile);
        }
        public void TestRotationAlongTheXAxis()
        {
            var inputPts      = new MdlFilePolygonDataReader(ExecutionDirInfoHelper.GetInputDirPath() + @"\1.mdl").Points;
            var outputDirPath = ExecutionDirInfoHelper.GetOutputDirPath() + @"\TestRotationAlongTheXAxis";

            if (!Directory.Exists(outputDirPath))
            {
                Directory.CreateDirectory(outputDirPath);
            }
            XamlWriter.WritePolygonsToXamlFile("", string.Format(@"{0}\Input.xaml", outputDirPath), inputPts, false);
            for (var angleInRadian = 0.0; angleInRadian <= Math.PI * 2; angleInRadian += Math.PI * 2.0 / 18.0)//every 20 degrees
            {
                var outputPts = RotateAlongXYOrZAxis.GetRotatedPtList(Axis.X, angleInRadian, inputPts.ToArray());
                XamlWriter.WritePolygonsToXamlFile("", string.Format(@"{0}\Output_X_{1}.xaml", outputDirPath, CommonFunctions.RadianToDegrees(angleInRadian, 0)), outputPts, false);
            }
        }
Example #8
0
        public void LeftAndRightMarkerPositionsTest()
        {
            var          backgroundColor = TestHelper.GetBackgroundColor();
            var          image           = TestHelper.GetStrippedTestImageForPerfectlyVerticalBase(backgroundColor);
            const string outputFile      = @"\LeftAndRightMarkerPositionsTest.png";

            var xPositions = MarkerProcessor.GetLeftAndRightMarkerPositions(image, 229, 581, 500, new MarkerProcessingParams());

            var g = Graphics.FromImage(image);

            foreach (var xPosition in xPositions)
            {
                g.DrawLine(Pens.Red, (int)xPosition, 0, (int)xPosition, image.Height - 1);
            }
            g.Dispose();

            image.Save(ExecutionDirInfoHelper.GetOutputDirPath() + outputFile);
        }
Example #9
0
        private static void RunTest(int minPixelsForBaseDisc, string filePath, string outputFileName)
        {
            var inputParams = new AutoConfigureImgPointsParams
            {
                BackgroundColor               = TestHelper.GetBackgroundColor(),
                MinPixelsForBaseDisc          = minPixelsForBaseDisc,
                MinPixelsForBaseDiscEndOfEdge = 10,
                ResizeHeight = null,
                ResizeWidth  = null,
                BackgroundStrippingParams = TestHelper.GetScreenBasedParamsForFirstMarioImage()
            };

            Bitmap image;

            if (inputParams.ResizeWidth.HasValue && inputParams.ResizeHeight.HasValue)
            {
                image = MainProcessor.ResizeJpg(filePath, null, inputParams.ResizeWidth.Value, inputParams.ResizeHeight.Value);
            }
            else
            {
                image = (Bitmap)Image.FromFile(filePath);
            }
            MainProcessor.StripBackground(image, inputParams.BackgroundStrippingParams);

            var calculator = new ClickPositionCalculator(image, inputParams);
            var topLeftEnd = calculator.GetDiscTopLeftEnd();

            Assert.IsNotNull(topLeftEnd);
            var topRightEnd = calculator.GetDiscTopRightEnd();

            Assert.IsNotNull(topRightEnd);

            var g = Graphics.FromImage(image);

            //g.FillEllipse(Brushes.Coral, topLeftEnd.Value.X - 8, topLeftEnd.Value.Y - 8, 16, 16);
            //g.FillEllipse(Brushes.Cyan, topRightEnd.Value.X - 8, topRightEnd.Value.Y - 8, 16, 16);
            g.DrawLine(Pens.White, topLeftEnd.Value.X, topLeftEnd.Value.Y, topRightEnd.Value.X, topRightEnd.Value.Y);

            g.Dispose();

            image.Save(ExecutionDirInfoHelper.GetOutputDirPath() + outputFileName);
        }
Example #10
0
        public void Create_Some_Rotated_Pts_Along_Z_Axis()
        {
            //translate to +y
            for (var ctr = 0; ctr < _ptsForACube.Count(); ctr++)
            {
                _ptsForACube[ctr].Y += 5.0;
            }
            var ptList = new List <Point3D>();

            for (var angle = 0.0; angle <= Math.PI; angle += Math.PI / 10)
            {
                Point3D[] rotatedPts = RotateAlongXYOrZAxis.GetRotatedPts(Axis.Z, angle, _ptsForACube);
                ptList.AddRange(rotatedPts);
            }
            XamlWriter.WritePolygonsToXamlFile(
                GetTemplatePath(),
                ExecutionDirInfoHelper.GetOutputDirPath() + @"\testRotationAlongZAxis.xaml",
                ptList,
                false);
        }
Example #11
0
        public void TestMarkerListForStrippedMarioImage()
        {
            var          backgroundColor = TestHelper.GetBackgroundColor();
            var          image           = TestHelper.GetStrippedFirstMarioImage(backgroundColor);
            const string outputFile      = @"\TestMarkerListForStrippedMarioImage.png";
            const int    targetYVal      = 20;

            var variations = ColorVariationCalculator.GetColorVariationList(image, 0, image.Width - 1, image.Height - targetYVal);

            var xPositions = MarkerProcessor.GetAllMarkerPositions(variations, new MarkerProcessingParams(), 0);

            var g = Graphics.FromImage(image);

            foreach (var xPosition in xPositions)
            {
                g.DrawLine(Pens.Red, (int)xPosition, 0, (int)xPosition, image.Height - 1);
            }
            g.Dispose();

            image.Save(ExecutionDirInfoHelper.GetOutputDirPath() + outputFile);
        }
        private static void RunTest(string inputFileName, string outputFileName, int variationPercent, Point imgLocationOfBaseColor)
        {
            var sourceImagePath = ExecutionDirInfoHelper.GetInputDirPath() + inputFileName;
            var bitmap          = (Bitmap)Image.FromFile(sourceImagePath);
            var backgroundColor = new SerializableColor(200, 200, 200);

            var @params = new BackgroundStrippingParams
            {
                BackgroundColor           = backgroundColor,
                ColorVariationBasedParams = new ColorVariationBasedParams
                {
                    VariationPercent = variationPercent,
                    CompareColor     = GetColor(bitmap.GetPixel(imgLocationOfBaseColor.X, imgLocationOfBaseColor.Y))
                }
            };

            BackgroundStripper.StripBackground(bitmap, @params);

            var targetPath = ExecutionDirInfoHelper.GetOutputDirPath() + outputFileName;

            bitmap.Save(targetPath);
        }
        private static void OutputDistances(Color backgroundColor, Bitmap image, int pixelsToFeed, string outputFileLeft, string outputFileRight)
        {
            var leftDistanceProcessor  = new LeftDistanceProcessor(backgroundColor, image, pixelsToFeed);
            var rightDistanceProcessor = new RightDistanceProcessor(backgroundColor, image, pixelsToFeed);

            var outputBitmapLeft  = new Bitmap(image.Width * 2, image.Height);
            var outputBitmapRight = new Bitmap(image.Width * 2, image.Height);

            for (var y = 0; y < image.Height; y++)
            {
                try
                {
                    var leftDistance = leftDistanceProcessor.GetDistance(y);
                    outputBitmapLeft.SetPixel(image.Width + (int)leftDistance, y, Color.Green);

                    var rightDistance = rightDistanceProcessor.GetDistance(y);
                    outputBitmapRight.SetPixel(image.Width + (int)rightDistance, y, Color.Green);
                }
                catch {}
            }
            outputBitmapLeft.Save(ExecutionDirInfoHelper.GetOutputDirPath() + outputFileLeft);
            outputBitmapRight.Save(ExecutionDirInfoHelper.GetOutputDirPath() + outputFileRight);
        }
Example #14
0
 public void SetUp()
 {
     _sourceDirPath = ExecutionDirInfoHelper.GetInputDirPath() + Comparisonwithimgwithoutmodel;
     _outputDirPath = ExecutionDirInfoHelper.GetOutputDirPath();
 }
Example #15
0
 public void SetUp()
 {
     _sourceDirPath = ExecutionDirInfoHelper.GetInputDirPath();
     _outputDirPath = ExecutionDirInfoHelper.GetOutputDirPath();
 }