コード例 #1
0
ファイル: GUI.cs プロジェクト: arocarlisle/OWG-Aim
        private void debugButton_Click(object sender, EventArgs e)
        {
            //Image<Bgr, Byte> test = new Image<Bgr, Byte>(CaptureScreen.GetDesktopImage(2));
            //CvInvoke.Imshow("test", test);
            //CvInvoke.WaitKey(0);
            //return;
            //interesting files: 31 57 58 60 62
            string debugpath = "C:\\Users\\Eric\\Desktop\\overwatch\\images\\templeofanubis\\78.bmp";

            //var debug =
            analyst.findSilhouettesWeak(
                analyst.hsvFilter(
                    new Image <Bgr, Byte>(debugpath)
                    )
                )
            ;
            //CvInvoke.Imshow("debug", debug);
            //CvInvoke.WaitKey(0);
            //return;
            analyst.silhouettes.ForEach(s =>
            {
                Image <Bgr, Byte> result = s.image.Convert <Bgr, Byte>();
                var marker    = new Bgr(0, 0, 255);
                s.centroid.Y += 4;
                //demo to show found top:
                if (s.centroid.X != -1)
                {
                    result[s.centroid.Y, s.centroid.X]     = marker;
                    result[s.centroid.Y + 1, s.centroid.X] = marker;
                    result[s.centroid.Y - 1, s.centroid.X] = marker;
                    result[s.centroid.Y, s.centroid.X + 1] = marker;
                    result[s.centroid.Y, s.centroid.X - 1] = marker;
                }
                CvInvoke.Imshow("Stats (C, L, G):\t" + s.count + ",\t" + s.linearness + ",\t" + s.gappiness, result);
                //CvInvoke.Imshow("head:\t" + s.centroid.X + ",\t" + s.centroid.Y, result);

                CvInvoke.WaitKey(0);
            });
            Console.WriteLine("done");
        }
コード例 #2
0
ファイル: Capturer.cs プロジェクト: arocarlisle/OWG-Aim
        public double safetyMargin = 1; //scaling factor for head movement
        private void act(Bitmap view)
        {
            //move recent screenshot to public view;
            if (saveMode)
            {
                view.Save(path + counter + ".bmp");
                counter++;
            }

            if (predictionMode)
            {
                int scale = (fastMode) ? 2 : 1;

                //find head during the first moment:
                Moment first     = CaptureScreen.GetDesktopMoment(scale);
                long   firstTime = first.timestamp;
                analyst.findSilhouettes(analyst.hsvFilter(new Image <Bgr, Byte>(first.image)));
                Point firstTarget = analyst.findTarget(center);
                if (firstTarget.X < 0 || firstTarget.Y < 0)
                {
                    return;
                }
                if (analyst.distance(firstTarget, center) > window)
                {
                    return;
                }

                //if that succeeded, find head during the second moment:
                Moment second     = CaptureScreen.GetDesktopMoment(scale);
                long   secondTime = second.timestamp;
                analyst.findSilhouettes(analyst.hsvFilter(new Image <Bgr, Byte>(second.image)));
                Point secondTarget = analyst.findTarget(firstTarget);
                if (secondTarget.X < 0 || secondTarget.Y < 0)
                {
                    return;
                }

                //then extrapolate the position of the head during the current time
                long   currentTime = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
                double xDelta      = (double)(secondTarget.X - firstTarget.X) / (double)(secondTime - firstTime); //x delta / ms
                double yDelta      = (double)(secondTarget.Y - firstTarget.Y) / (double)(secondTime - firstTime); //x delata / ms

                xDelta *= safetyMargin;
                yDelta *= safetyMargin;

                double elapsedTime = travelTime + (currentTime - secondTime);
                int    newX        = (int)((double)secondTarget.X + (xDelta * elapsedTime));
                int    newY        = (int)((double)secondTarget.Y + (yDelta * elapsedTime));

                if (fastMode)
                {
                    newX += center.X / 2;
                    newY += center.Y / 2;
                }

                mouseMover.newMove(newX, newY, killMode);//move to calculated position
            }
            else
            {
                //builds List<Silhouette> of targets
                analyst.findSilhouettes(analyst.hsvFilter(new Image <Bgr, Byte>(view)));
                Point target = analyst.findTarget(center);

                if (target.X < 0 || target.Y < 0)
                {
                    return;
                }
                if (analyst.distance(target, center) > window)
                {
                    return;
                }

                //MessageBox.Show("moved to\t" + target.X + "\t" + target.Y);

                if (fastMode)
                {
                    target.X += center.X / 2;
                    target.Y += center.Y / 2;
                }
                if (honeMode)
                {
                    mouseMover.newMoveFast(target.X, target.Y);
                    System.Threading.Thread.Sleep(30);
                    Image <Bgr, Byte> subImage = new Image <Bgr, Byte>(CaptureScreen.GetDesktopImage(4));
                    analyst.findSilhouettesWeak(analyst.hsvFilter(subImage));
                    target    = analyst.findTarget(center);
                    target.X += center.X * 3 / 4;
                    target.Y += center.Y * 3 / 4;
                    //MessageBox.Show("wants to go to\t" + target.X + "\t" + target.Y);
                    if (target.X < 0 || target.Y < 0)
                    {
                        //Console.WriteLine("hone failed");
                        mouseMover.newMove(center.X, center.Y, killMode);//shoot in place if target isn't found again
                    }
                    else
                    {
                        mouseMover.newMove(target.X, target.Y, killMode);//otherwise hone in
                    }
                }
                else
                {
                    mouseMover.newMove(target.X, target.Y, killMode);
                }
            }
        }