示例#1
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);
        }
        private void Return(object sender, RoutedEventArgs routedEventArgs)
        {
            if (_minPixelsForBaseDisc == null)
            {
                MessageBox.Show("Please mark the area in the image that contains just the base disc.");
                return;
            }
            else if (_minPixelsForBaseDisc < 10)
            {
                MessageBox.Show("The height of the base disc should at least be 10 pixels.");
                return;
            }

            var quickProcessingWindow  = new QuickProcessingWindowHelper(ParentCanvas);
            var processor              = new AutoConfigureImgPoints.Processor();
            var markerPrcoessingParams = new MarkerProcessingParams
            {
                MarkerColorVariationPercent = 10,
                MarkerWidthPercent          = 5,
                MaximumMarkerCount          = 10
            };
            var @params = new AutoConfigureImgPointsParams
            {
                MarkerProcessingParams        = markerPrcoessingParams,
                BackgroundColor               = _backgroundColor,
                BackgroundStrippingParams     = _backgroundStrippingParams,
                MinPixelsForBaseDisc          = _minPixelsForBaseDisc.Value,
                MinPixelsForBaseDiscEndOfEdge = 10,
                ResizeHeight = 500,
                ResizeWidth  = 500
            };
            var clickPositions = processor.GetClickPositionsForImgFolder(_folderPath, @params);



            var gotResults = clickPositions != null && clickPositions.Count > 0 &&
                             clickPositions.Any(x => (x.ClickPositionListForImages != null && x.ClickPositionListForImages.Count > 0));

            if (!gotResults)
            {
                var statusMessages = new List <string>
                {
                    "Autoconfigure was unsuccessful. No image positions could be determined.",
                    "Please click on the 'Requirements' button to check how to take photos to support autoconfigure.",
                    "Press the cancel button to go back to entering the positions manually."
                };
                quickProcessingWindow.Close();
                var messageBox = new HelpMessageBox(statusMessages, null);
                messageBox.ShowDialog();
                return;
            }

            var fileCount           = GetImageFilesHelper.GetImageFilesFromLocation(_folderPath);
            var requiredCount       = GetRequiredClickInputsCount(fileCount);
            var identifiedCount     = 0;
            var innerStatusMessages = new List <string>();

            for (var ctr = 0; ctr < clickPositions.Count; ctr++)
            {
                var clickInput = clickPositions[ctr];
                var count      = clickInput != null && clickInput.ClickPositionListForImages != null? clickInput.ClickPositionListForImages.Count : 0;
                identifiedCount += count;

                if (ctr == 0)
                {
                    innerStatusMessages.Add(string.Format("{0}: {1} identified out of required 5.", clickInput == null? (ctr + 1).ToString() : clickInput.ImageName, count));
                }
                else
                {
                    innerStatusMessages.Add(string.Format("{0}: {1} identified out of required 4.", clickInput == null ? (ctr + 1).ToString() : clickInput.ImageName, count));
                }
            }

            quickProcessingWindow.Close();

            if (identifiedCount == requiredCount)
            {
                var statusMessages = new List <string>
                {
                    "AutoConfigure Successful!",
                    string.Format("All required {0} click positions were identified.", requiredCount),
                    "We will now display all the click positions for your review.."
                };

                var messageBox = new HelpMessageBox(statusMessages, null);
                messageBox.ShowDialog();
            }
            else
            {
                var statusMessages = new List <string>
                {
                    "AutoConfigure was partially successful in identifying the click positions.",
                    string.Format("{0} out of total of {1} positions could be identified.", identifiedCount, requiredCount),
                    "Below is a break down of the identified positions.",
                    "Click close to to review the identified positions and fill in the missed ones..."
                };

                var messageBox = new HelpMessageBox(statusMessages, innerStatusMessages);
                messageBox.ShowDialog();
            }

            if (AutoConfigured != null)
            {
                AutoConfigured(this,
                               new AutoConfigureSettingsEventArgs
                {
                    ClickInputs = new ClickInputs
                    {
                        ImageClickInputDetailsList = clickPositions,
                        Angles = null
                    }
                });
            }
        }