Ejemplo n.º 1
0
        void hotKey_OnHotkey(int hotKeyID)
        {
            switch (dicKeys[hotKeyID])
            {
            case Keys.Home:
            {
                MouseInvoke.InitApp(AppInvoke.Init());
                rectMain = AppInvoke.Rectangle;
                this.picModify.Height = rectMain.Height * this.picModify.Width / rectMain.Width;
                inRun = true;
                RefreshState();
            }
            break;

            case Keys.End:
            {
                inRun = false;
                RefreshState();
            }
            break;

            case Keys.X:
            {
                this.labPos.Text = $"{MousePosition.X - rectMain.X},{ MousePosition.Y - rectMain.Y }";
            }
            break;
            }
        }
Ejemplo n.º 2
0
 private void FrmMain_Load(object sender, EventArgs e)
 {
     Task.Factory.StartNew(() =>
     {
         var hWnd = AppInvoke.Init();
         MouseInvoke.InitApp(hWnd);
         var rect   = AppInvoke.Rectangle;
         var g      = Graphics.FromHwnd(hWnd);
         var pArray = new Point[4];
         var w      = rect.Width / 4;
         for (int i = 0; i < pArray.Length; i++)
         {
             pArray[i] = new Point(w / 2 + i * w, rect.Height * 2 / 3);
         }
         while (true)
         {
             if (!isRun)
             {
                 autoResetEvent.WaitOne();
             }
             Process(g, pArray);
             ShowGrid(g, w, pArray);
             Thread.Sleep(1);
         }
     });
 }
Ejemplo n.º 3
0
 void Process(Graphics g, Point[] pArr)
 {
     for (int i = 0; i < pArr.Length; i++)
     {
         var c     = AppInvoke.GetColor(pArr[i].X - 10, pArr[i].Y - 10);
         var isHit = c.R < 50 && c.G < 50 && c.B < 50;
         if (isHit)
         {
             g.FillEllipse(Brushes.White, pArr[i].X + 5, pArr[i].Y + 5, 10, 10);
             MouseInvoke.AppClick(pArr[i].X, pArr[i].Y);
         }
         else
         {
             g.DrawEllipse(Pens.White, pArr[i].X + 5, pArr[i].Y + 5, 10, 10);
         }
     }
 }
Ejemplo n.º 4
0
        private void PickFishAndRubbish()
        {
            var bmp     = new Bitmap(AppInvoke.GetImage());
            var bmpShow = bmp.Clone() as Image;
            var g       = Graphics.FromImage(bmpShow);

            //灰度化
            bmp = Grayscale.CommonAlgorithms.BT709.Apply(bmp);
            //反色
            new Invert().ApplyInPlace(bmp);
            //二值化
            new Threshold(120).ApplyInPlace(bmp);
            //保存模板以用于识别
            //bmp.Save("template.bmp");
            //fish
            var matchArray = new AForge.Imaging.ExhaustiveTemplateMatching(0.8f).ProcessImage(bmp, dicTemplate["fish"]);

            foreach (var m in matchArray)
            {
                g.FillRectangle(Brushes.Red, m.Rectangle);
                MoveAndClick(m.Rectangle.X + m.Rectangle.Width / 2, m.Rectangle.Y + m.Rectangle.Height / 2, 0);
            }
            //Rubbish
            matchArray = new AForge.Imaging.ExhaustiveTemplateMatching(0.88f).ProcessImage(bmp, dicTemplate["banana"]);
            foreach (var m in matchArray)
            {
                g.FillRectangle(Brushes.Yellow, m.Rectangle);
                MoveAndClick(m.Rectangle.X + m.Rectangle.Width / 2, m.Rectangle.Y + m.Rectangle.Height / 2, 0);
            }
            matchArray = new AForge.Imaging.ExhaustiveTemplateMatching(0.88f).ProcessImage(bmp, dicTemplate["bag"]);
            foreach (var m in matchArray)
            {
                g.FillRectangle(Brushes.Green, m.Rectangle);
                MoveAndClick(m.Rectangle.X + m.Rectangle.Width / 2, m.Rectangle.Y + m.Rectangle.Height / 2, 0);
            }
            matchArray = new AForge.Imaging.ExhaustiveTemplateMatching(0.88f).ProcessImage(bmp, dicTemplate["can"]);
            foreach (var m in matchArray)
            {
                g.FillRectangle(Brushes.Green, m.Rectangle);
                MoveAndClick(m.Rectangle.X + m.Rectangle.Width / 2, m.Rectangle.Y + m.Rectangle.Height / 2, 0);
            }
            this.Invoke(new Action(() =>
            {
                this.picModify.Image = bmpShow;
            }));
        }