BoringHeroes.ScreenReader.UpdateUnits C# (CSharp) Метод

UpdateUnits() публичный статический Метод

public static UpdateUnits ( CurrentGameState state ) : void
state BoringHeroes.GameLogic.CurrentGameState
Результат void
        public static void UpdateUnits(CurrentGameState state)
        {
            TickNow();
            var unitPoints = new List<System.Drawing.Point>();
            if (ShouldBringToFront) ControlInput.BringHeroesToFront();
            var src = GrabScreenGDI(new Rectangle(0, 100, 1024, 400));
            var sourceImage = ChangePixelFormat(src, PixelFormat.Format24bppRgb);

            if (false)
            {
                Tools.HSLFiltering.Hue = new IntRange(358, 5);
                Tools.HSLFiltering.Saturation = new Range(0.3f, 1);
                Tools.HSLFiltering.Luminance = new Range(0, 0.4f);
                Tools.HSLFiltering.ApplyInPlace(sourceImage);
            }
            Tools.ColorFilter.Red = new IntRange(140, 180);
            Tools.ColorFilter.Green = new IntRange(0, 50);
            Tools.ColorFilter.Blue = new IntRange(0, 50);
            Tools.ColorFilter.ApplyInPlace(sourceImage);

            var grayScale = Grayscale.CommonAlgorithms.BT709.Apply(sourceImage);
            /*Tools.Thresholder.ThresholdValue = 1;
            Tools.Thresholder.ApplyInPlace(grayScale);
            Tools.HLengthSmoothing.MaxGapSize = 2;
            Tools.VLengthSmoothing.MaxGapSize = 2;
            Tools.HLengthSmoothing.ApplyInPlace(grayScale);
            Tools.VLengthSmoothing.ApplyInPlace(grayScale);*/
            var thresholded = Tools.GSToRgb.Apply(grayScale);
            var bc = new BlobCounter();
            bc.ProcessImage(thresholded);
            var blobs = bc.GetObjectsInformation().ToList();
            var gc = Graphics.FromImage(sourceImage);
            try
            {
                blobs =
                    blobs.Where(
                        o =>
                            !o.Rectangle.IntersectsWith(state.GameMode.MinimapRectangle) && o.Rectangle.Width > 4 &&
                            o.Rectangle.Width < 35 && o.Rectangle.Height == 1).ToList();
                var i = 0;
                foreach (var blob in blobs)
                {
                    unitPoints.Add(new System.Drawing.Point((int) (blob.CenterOfGravity.X),
                        (int) (100 + blob.CenterOfGravity.Y)));
                    //gc.DrawEllipse(new Pen(Color.White), blob.Rectangle.X - 4, blob.Rectangle.Y - 4, 8, 8 );
                }
            }
            catch (Exception e)
            {
            }

            //gc.Flush();
            state.EnemyCreepsNearby = unitPoints.ToArray();
            //sourceImage.Save("./debug/go.png");

            unitPoints.Clear();

            if (ShouldBringToFront) ControlInput.BringHeroesToFront();
            try
            {
                sourceImage = ChangePixelFormat(src, PixelFormat.Format24bppRgb);
                if (false)
                {
                    Tools.HSLFiltering.Hue = new IntRange(112, 128);
                    Tools.HSLFiltering.Saturation = new Range(0.8f, 1);
                    Tools.HSLFiltering.Luminance = new Range(0, 0.4f);
                    Tools.HSLFiltering.ApplyInPlace(sourceImage);
                }
                Tools.ColorFilter.Red = new IntRange(0, 50);
                Tools.ColorFilter.Green = new IntRange(120, 160);
                Tools.ColorFilter.Blue = new IntRange(0, 50);
                Tools.ColorFilter.ApplyInPlace(sourceImage);
                grayScale = Grayscale.CommonAlgorithms.BT709.Apply(sourceImage);
                /*Tools.Thresholder.ThresholdValue = 1;
                Tools.Thresholder.ApplyInPlace(grayScale);
                Tools.HLengthSmoothing.MaxGapSize = 2;
                Tools.VLengthSmoothing.MaxGapSize = 2;
                Tools.HLengthSmoothing.ApplyInPlace(grayScale);
                Tools.VLengthSmoothing.ApplyInPlace(grayScale);*/
                thresholded = Tools.GSToRgb.Apply(grayScale);

                bc = new BlobCounter();
                bc.ProcessImage(thresholded);
                //thresholded.Save("./images/unitdebug.png");
                blobs = bc.GetObjectsInformation().ToList();

                blobs =
                    blobs.Where(
                        o =>
                            !o.Rectangle.IntersectsWith(state.GameMode.MinimapRectangle) && o.Rectangle.Width > 4 &&
                            o.Rectangle.Width < 35 && o.Rectangle.Height >= 2 && o.Rectangle.Height < 4).ToList();
                var i = 0;
                foreach (var blob in blobs)
                {
                    unitPoints.Add(new System.Drawing.Point((int) (blob.CenterOfGravity.X - 12),
                        (int) (100 + blob.CenterOfGravity.Y)));
                }
            }
            catch (Exception e)
            {
            }
            state.FriendlyCreepsNearby = unitPoints.ToArray();
            MainWindow.DebugReaderStats("Units:" + TickNow());
        }