示例#1
0
文件: Mask.cs 项目: Nekohim3/BDOA
 public bool Compare(Sbmp b, int x, int y)
 {
     if (x + Width > b.Width || y + Height > b.Height)
     {
         return(false);
     }
     for (int i = x, ii = 0; ii < Width; i++, ii++)
     {
         for (int j = y, jj = 0; jj < Height; j++, jj++)
         {
             var c = b.GetPixel(i, j);
             if (Types[Colors[ii, jj]].A == 0)
             {
                 if (Types.Count(v => v == c) != 0)
                 {
                     return(false);
                 }
             }
             else
             {
                 if (c != Types[Colors[ii, jj]])
                 {
                     return(false);
                 }
             }
         }
     }
     return(true);
 }
示例#2
0
        private string GetCaptcha()
        {
            CheckLic();
            var b   = new Sbmp(_sc);
            var bcl = b.Crop(_bdoWindow.LCaptcha);
            var bcr = b.Crop(_bdoWindow.RCaptcha);

            bcl = ImgHelpers.Threshold(bcl);
            bcr = ImgHelpers.Threshold(bcr);
            bcl = bcl.Crop(ImgHelpers.GetRect(bcl));
            bcr = bcr.Crop(ImgHelpers.GetRect(bcr));
            var s = _tr.Recognize(bcl);

            if (s == "-")
            {
                bcl.GetBmp().Save(DateTime.Now.ToShortTimeString() + "l.bmp");
            }
            s += _tr.Recognize(bcr);
            if (s[1] == '-')
            {
                bcr.GetBmp().Save(DateTime.Now.ToShortTimeString() + "r.bmp");
            }
            bcl.Dispose();
            bcr.Dispose();
            b.Dispose();
            return(s);
        }
示例#3
0
文件: Mask.cs 项目: Nekohim3/BDOA
        public bool Compare(Sbmp b, int x, int y, int threshold, int npc)
        {
            if (x + Width > b.Width || y + Height > b.Height)
            {
                return(false);
            }
            var counter = 0;

            for (int i = x, ii = 0; ii < Width; i++, ii++)
            {
                for (int j = y, jj = 0; jj < Height; j++, jj++)
                {
                    var c = b.GetPixel(i, j);
                    var e = Types[Colors[ii, jj]];
                    if (Math.Abs(c.R - e.R) <= threshold && Math.Abs(c.G - e.G) <= threshold &&
                        Math.Abs(c.B - e.B) <= threshold)
                    {
                        counter++;
                    }
                }
            }
            double all  = Width * Height;
            var    proc = counter * 100 / all;

            return(proc >= npc);
        }
示例#4
0
        internal static Rectangle GetRect(Sbmp b)
        {
            var x = -1;
            var w = -1;

            for (var i = 0; i < b.Width; i++)
            {
                var counter = 0;
                for (var j = 0; j < b.Height; j++)
                {
                    if (b.GetPixel(i, j).R != 255 && x == -1)
                    {
                        x = i;
                        w = 0;
                        break;
                    }
                    if (x != -1 && b.GetPixel(i, j).R == 255)
                    {
                        counter++;
                    }
                }
                if (counter != b.Height)
                {
                    w++;
                }
                else
                {
                    break;
                }
            }
            var y = -1;
            var h = -1;

            for (var j = 0; j < b.Height; j++)
            {
                var counter = 0;
                for (var i = 0; i < b.Width; i++)
                {
                    if (b.GetPixel(i, j).R != 255 && y == -1)
                    {
                        y = j;
                        h = 0;
                        break;
                    }
                    if (y != -1 && b.GetPixel(i, j).R == 255)
                    {
                        counter++;
                    }
                }
                if (counter != b.Width)
                {
                    h++;
                }
                else
                {
                    break;
                }
            }
            return(new Rectangle(x, y, w, h));
        }
示例#5
0
 internal AItem()
 {
     _un  = true;
     Img  = new Sbmp(Properties.Resources.unk);
     ImgS = Img.Crop(new Rectangle(13, 12, 37, 37));
     G    = new Grid
     {
         Width  = 246,
         Height = 60,
         HorizontalAlignment = HorizontalAlignment.Left,
         VerticalAlignment   = VerticalAlignment.Top
     };
     ImgL = new Image
     {
         Width  = 200,
         Height = 60,
         HorizontalAlignment = HorizontalAlignment.Left,
         VerticalAlignment   = VerticalAlignment.Top,
         Source = ImgHelpers.BitmapToImageSource(Img.GetBmp()),
         Margin = new Thickness(0, 0, 0, 0)
     };
     ImgX = new Image
     {
         Width  = 46,
         Height = 60,
         HorizontalAlignment = HorizontalAlignment.Left,
         VerticalAlignment   = VerticalAlignment.Top,
         Source = ImgHelpers.BitmapToImageSource(Properties.Resources.del),
         Margin = new Thickness(200, 0, 0, 0)
     };
     RenderOptions.SetBitmapScalingMode(ImgL, BitmapScalingMode.HighQuality);
     RenderOptions.SetBitmapScalingMode(ImgX, BitmapScalingMode.HighQuality);
     G.Children.Add(ImgL);
     G.Children.Add(ImgX);
 }
示例#6
0
文件: Mask.cs 项目: Nekohim3/BDOA
 public bool Compare(Sbmp b, Rectangle r, out Point pt)
 {
     for (var i = r.X; i <= r.X + r.Width - Width; i++)
     {
         for (var j = r.Y; j <= r.Y + r.Height - Height; j++)
         {
             if (Compare(b, i, j))
             {
                 pt = new Point(i, j);
                 return(true);
             }
         }
     }
     pt = new Point(-1, -1);
     return(false);
 }
示例#7
0
 public bool Compare(Sbmp b, Rectangle r)
 {
     for (int i = 0, ii = r.X; i < Width; i++, ii++)
     {
         for (int j = 0, jj = r.Y; j < Height; j++, jj++)
         {
             var c = b.GetPixel(ii, jj);
             var e = GetPixel(i, j);
             if (c != e)
             {
                 return(false);
             }
         }
     }
     return(true);
 }
示例#8
0
        internal NeuroData(Sbmp b, int num)
        {
            Numb   = num.ToString();
            Width  = b.Width;
            Height = b.Height;
            _buf   = new byte[b.Width * b.Height];
            var counter = 0;

            for (var i = 0; i < Width; i++)
            {
                for (var j = 0; j < Height; j++)
                {
                    _buf[counter] = b.GetPixel(i, j).R == 255 ? (byte)0 : (byte)1;
                    counter++;
                }
            }
            Train(num);
        }
示例#9
0
 private void AddItem(Sbmp b)
 {
     if (_listByuing)
     {
         return;
     }
     Dispatcher.Invoke(() =>
     {
         if (b != null)
         {
             if (!_bitems.Any(q => q.ImgS.Compare(b, new Rectangle(13, 12, 37, 37), 25, 100)))
             {
                 _bitems.Add(new AItem(b, (int)Items.ActualWidth));
             }
         }
         BoardRefresh();
     });
 }
示例#10
0
        internal static Sbmp Threshold(Sbmp bq)
        {
            var b = bq.Copy();

            for (var i = 0; i < b.Width; i++)
            {
                for (var j = 0; j < b.Height; j++)
                {
                    var c = b.GetPixel(i, j);
                    if (Math.Abs(c.R - c.G) < 120 && Math.Abs(c.G - c.B) < 120 && Math.Abs(c.R - c.B) < 120)
                    {
                        b.SetPixel(i, j, Color.FromArgb(255, 255, 255, 255));
                    }
                    else
                    {
                        b.SetPixel(i, j, Color.FromArgb(255, 0, 0, 0));
                    }
                }
            }
            return(b);
        }
示例#11
0
        internal string Recognize(Sbmp b)
        {
            double    proc = 0;
            NeuroData td   = null;

            foreach (var t in Td)
            {
                if (t.Width != b.Width || t.Height != b.Height)
                {
                    continue;
                }
                var p = t.Recognize(b);
                if (!(p > proc))
                {
                    continue;
                }
                proc = p;
                td   = t;
            }
            return(proc >= 95 ? td?.Numb : "-");
        }
示例#12
0
        public bool Compare(Sbmp b, Rectangle r, int threshold, int npc)
        {
            var counter = 0;

            for (int i = 0, ii = r.X; i < Width; i++, ii++)
            {
                for (int j = 0, jj = r.Y; j < Height; j++, jj++)
                {
                    var c = b.GetPixel(ii, jj);
                    var e = GetPixel(i, j);
                    if (Math.Abs(c.R - e.R) <= threshold && Math.Abs(c.G - e.G) <= threshold &&
                        Math.Abs(c.B - e.B) <= threshold)
                    {
                        counter++;
                    }
                }
            }
            double all  = Width * Height;
            var    proc = counter * 100 / all;

            return(proc >= npc);
        }
示例#13
0
        internal double Recognize(Sbmp b)
        {
            if (Width != b.Width || Height != b.Height)
            {
                return(-1);
            }
            var counter = 0;
            var scount  = 0;

            for (var i = 0; i < Width; i++)
            {
                for (var j = 0; j < Height; j++)
                {
                    if (_buf[counter] == (b.GetPixel(i, j).R == 255 ? 0 : 1))
                    {
                        scount++;
                    }
                    counter++;
                }
            }
            return(scount * (double)100 / counter);
        }
示例#14
0
        internal WindowState WindState(DxScreenCapture sc)
        {
            var b = new Sbmp(sc);

            if (_mfiltr.Compare(b, Filtr))
            {
                if (_mrefr.Compare(b, Refr))
                {
                    Point pt;
                    if (_mcap.Compare(b, PCap, out pt))
                    {
                        Cap      = new Rectangle(pt.X, pt.Y, 41, 6);
                        LCaptcha = new Rectangle(Cap.X, Cap.Y - 49, 85, 33);
                        RCaptcha = new Rectangle(Cap.X + 85, Cap.Y - 49, 85, 33);
                        Min      = new Rectangle(Cap.X + 245, Cap.Y - 119, 0, 0);
                        CountF   = new Rectangle(Cap.X + 166, Cap.Y - 105, 0, 0);
                        CaptchaF = new Rectangle(Cap.X + 205, Cap.Y - 33, 0, 0);
                        count    = _mmin.Compare(b, Min);
                        Ws       = WindowState.Buying;
                    }
                    else
                    {
                        Ws = WindowState.Lots;
                    }
                }
                else
                {
                    Ws = WindowState.Main;
                }
            }
            else
            {
                Ws = WindowState.None;
            }
            return(Ws);
        }
示例#15
0
 private void Add(Sbmp b, int num)
 {
     Td.Add(new NeuroData(b, num));
 }
示例#16
0
 private void BuyingProc()
 {
     CheckLic();
     while (_bitems.Count != 0 && _listByuing && _state == State.On)
     {
         var b = new Sbmp(_sc);
         for (var i = 0; i < 7 && _listByuing; i++)
         {
             try
             {
                 for (var j = 0; j < _bitems.Count && _listByuing; j++)
                 {
                     var q = _bitems[j];
                     if (q._un)
                     {
                         var c = b.GetPixel(_bdoWindow.CAX - 270, _bdoWindow.CAY - 157 + i * 62);
                         if (c.R == c.G || c.G == c.B)
                         {
                             continue;
                         }
                         Exec(i);
                         Dispatcher.Invoke(() =>
                         {
                             if (_bstate == BState.DelRes)
                             {
                                 DelItem(j);
                             }
                             if (_bstate == BState.Stop)
                             {
                                 DelAllItem();
                             }
                         });
                         throw new InvalidOperationException();
                     }
                     else
                     {
                         if (
                             !q.ImgS.Compare(b,
                                             new Rectangle(_bdoWindow.CAX - 267, _bdoWindow.CAY - 155 + i * 62, 150, 37), 25,
                                             100))
                         {
                             continue;
                         }
                         Exec(i);
                         //if (s == BuyMessage.Bought)
                         Dispatcher.Invoke(() =>
                         {
                             if (_bstate == BState.DelRes)
                             {
                                 DelItem(j);
                             }
                             if (_bstate == BState.Stop)
                             {
                                 DelAllItem();
                             }
                         });
                         throw new InvalidOperationException();
                     }
                 }
             }
             catch (InvalidOperationException)
             {
                 break;
             }
         }
     }
     _listByuing = false;
     Dispatcher.Invoke(() =>
     {
         LABSS.Content    = "[Выкл]";
         LABSS.Foreground = new SolidColorBrush(Color.FromArgb(0xff, 0xee,
                                                               0x22, 0x22));
         IStartBack.Source = ImgHelpers.BitmapToImageSource(Properties.Resources.startback);
     });
 }