Пример #1
0
        public void SetTargetAndShot(Mat target, int czteryIpol, TargetDetails targetDet)
        {
            targetMat            = target;
            TargetDet            = targetDet;
            pictureBTarget.Image = target.Bitmap;

            rozmiarObrazka = czteryIpol * 2 + 1;
            Bitmap flag = new Bitmap(rozmiarObrazka, rozmiarObrazka);
            // Bitmap flag = new Bitmap(101, 101);
            Graphics flagGraphics = Graphics.FromImage(flag);

            // Create solid brush.
            // SolidBrush blueBrush = new SolidBrush(Color.Blue);
            //  flagGraphics.FillRectangle(blueBrush, new Rectangle(0, 0, rozmiarObrazka, rozmiarObrazka));



            Rectangle rectangle = new Rectangle(0, 0, czteryIpol * 2, czteryIpol * 2);

            // flagGraphics.fil
            // Rectangle rectangle = new Rectangle(0, 0, 100,100);
            flagGraphics.DrawEllipse(new Pen(Color.Red, 1), rectangle);
            ShotMark = flag;
        }
Пример #2
0
        public static ProcessFrameResult ManualProcessFrame(Mat frame, int firstCannyThresh = 100, int secondCannyThresh = 60, int firstCannyThresh1 = 120, int secondCannyThresh1 = 50, TargetDetails useThisTarget = null)
        {
            PointF[] srcVertices;
            int      kwadratWidth;

            srcVertices = useThisTarget.TargetRect;
            if (srcVertices == null)
            {
                return(null);
            }
            kwadratWidth = Convert.ToInt32(srcVertices[2].X - srcVertices[3].X);


            #region wyznaczenie prostokatow i kwadratow do transformacji perspektywy

            PointF[] dstVertices = new PointF[] {
                new PointF(0, 0),                       //tl topleft
                new PointF(kwadratWidth, 0),            //tr
                new PointF(kwadratWidth, kwadratWidth), //br
                new PointF(0, kwadratWidth)
            };                                          //bl


            #endregion wyznaczenie prostokatow i kwadratow do transformacji perspektywy

            #region tranformacja perspektywy
            Mat  warpMatrix = CvInvoke.GetPerspectiveTransform(srcVertices, dstVertices);
            Mat  warped     = new Mat();
            Size size       = new Size(kwadratWidth, kwadratWidth);
            CvInvoke.WarpPerspective(frame, warped, warpMatrix, size, Inter.Linear, Warp.Default);
            // result.Warped = warped;//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
            #endregion tranformacja perspektywy


            return(ProcessFromFile(warped, firstCannyThresh, secondCannyThresh, firstCannyThresh1, secondCannyThresh1, useThisTarget));
        }
Пример #3
0
        public static Shot WyliczWartoscPrzestrzeliny(PointF shotPoint, TargetDetails targetDet)
        {
            double wartosc = 0;
            Shot   sh      = new Shot();
            double pix     = Pix(targetDet.BlackR);



            Point  shotCenter = Point.Round(shotPoint);
            var    diffX      = shotCenter.X - targetDet.BlackCenter.X;
            var    diffY      = shotCenter.Y - targetDet.BlackCenter.Y;
            double odlegl     = Math.Sqrt(Math.Pow(diffX, 2) + Math.Pow(diffY, 2));

            sh.Length = odlegl * pix;

            double dziesietna  = (restRingWidth / pix) / 2; //dziesietna dla pierscieni 9 --
            double dziesietna1 = dziesietna / 10;

            double dziesietna10  = ((tenRingWidth + innerTen) / pix) / 2;// dziesietna dla 10
            double dziesietna11  = dziesietna10 / 10;
            double czteryiPolmmR = FourNHalfR(pix);
            double dl            = odlegl - czteryiPolmmR;

            //  Point strzalObliczonyOdSrodka = new Point(center.X + diffX, center.Y + diffY);

            Point strzalObliczonyOdSrodkaPix;

            if (targetDet.CameraFlipped)
            {
                strzalObliczonyOdSrodkaPix = new Point(-Convert.ToInt32(diffX * pix), -Convert.ToInt32(diffY * pix));
            }
            else
            {
                strzalObliczonyOdSrodkaPix = new Point(Convert.ToInt32(diffX * pix), Convert.ToInt32(diffY * pix));
            }

            sh.PointFromCenter = strzalObliczonyOdSrodkaPix;

            //sprawdzenie wartości strzału
            if (dl <= TenR(pix))
            {
                wartosc = CountdziesietneDycha(10, odlegl, czteryiPolmmR, TenR(pix), dziesietna11, InnerTenR(pix));
            }
            else if (dl <= NineR(pix))
            {
                wartosc = Countdziesietne(9, odlegl, czteryiPolmmR, NineR(pix), dziesietna1);
            }
            else if (dl <= EightR(pix))
            {
                wartosc = Countdziesietne(8, odlegl, czteryiPolmmR, EightR(pix), dziesietna1);
            }
            else if (dl <= SevenR(pix))
            {
                wartosc = Countdziesietne(7, odlegl, czteryiPolmmR, SevenR(pix), dziesietna1);
            }
            else if (dl <= SixR(pix))
            {
                wartosc = Countdziesietne(6, odlegl, czteryiPolmmR, SixR(pix), dziesietna1);
            }
            else if (dl <= FiveR(pix))
            {
                wartosc = Countdziesietne(5, odlegl, czteryiPolmmR, FiveR(pix), dziesietna1);
            }
            else if (dl <= FourR(pix))
            {
                wartosc = Countdziesietne(4, odlegl, czteryiPolmmR, FourR(pix), dziesietna1);
            }
            else if (dl <= ThreeR(pix))
            {
                wartosc = Countdziesietne(3, odlegl, czteryiPolmmR, ThreeR(pix), dziesietna1);
            }
            else if (dl <= TwoR(pix))
            {
                wartosc = Countdziesietne(2, odlegl, czteryiPolmmR, TwoR(pix), dziesietna1);
            }
            else if (dl <= OneR(pix))
            {
                wartosc = Countdziesietne(1, odlegl, czteryiPolmmR, OneR(pix), dziesietna1);
            }


            sh.Value = wartosc;
            sh.Time  = DateTime.Now.Ticks;
            return(sh);
        }
Пример #4
0
        public static int GetCzteryIpolmmR_int(TargetDetails settings)
        {
            var pix = CaptureHelper.Pix(settings.BlackR);

            return(Convert.ToInt32(CaptureHelper.FourNHalfR(pix)));
        }
Пример #5
0
        public static ProcessFrameResult ProcessFromFile(Mat frame, int firstCannyThresh = 100, int secondCannyThresh = 60, int firstCannyThresh1 = 120, int secondCannyThresh1 = 50, TargetDetails useThisTarget = null)
        {
            ProcessFrameResult result = new ProcessFrameResult();

            result.Target             = new TargetDetails();
            result.Target.BlackCenter = useThisTarget.BlackCenter;
            result.Target.BlackR      = useThisTarget.BlackR;

            var pix               = Pix(useThisTarget.BlackR);
            int zapasSize         = 5; //zapas z jakim ma wykrywać przestrzeline - to wywalić do jakiegoś txtbox czy coś
            int czteryIpolmmR_int = Convert.ToInt32(FourNHalfR(pix));


            Mat circleImage = frame;

            #region hocki klocki przepierdalanie obrazu

            var inputImage = frame.ToImage <Bgr, byte>();
            // inputImage._EqualizeHist();
            inputImage._GammaCorrect(0.4d);
            result.GrSmootWarped = inputImage.Mat;

            #region blur gray canny samej tarczy

            Mat canny_output12 = new Mat();
            //As for your answer to number two, blur the image, convert to greyscale, then threshold to eliminate lighting differences is the usual solution

            Mat smallGrayFrame12    = new Mat();
            Mat smoothedGrayFrame12 = new Mat();
            CvInvoke.PyrDown(inputImage.Mat, smallGrayFrame12);
            CvInvoke.PyrUp(smallGrayFrame12, smoothedGrayFrame12);
            CvInvoke.CvtColor(smoothedGrayFrame12, smoothedGrayFrame12, ColorConversion.Bgr2Gray);
            // CvInvoke.GaussianBlur(smoothedGrayFrame12, smoothedGrayFrame12, new Size(9, 9), 1, 1);
            result.SmoothedOryginal = smoothedGrayFrame12;


            #region test
            //#######test

            //                   double otsu_thresh_val12 = CvInvoke.Threshold(smoothedGrayFrame12, fake12, firstCannyThresh, secondCannyThresh, ThresholdType.Binary & ThresholdType.Otsu);
            //CvInvoke.AdaptiveThreshold(smoothedGrayFrame12, fake12, 255, AdaptiveThresholdType.GaussianC, ThresholdType.BinaryInv, 3, 2);
            //1CvInvoke.GaussianBlur(fake12, fake12, new Size(9, 9), 1, 1);
            //  CvInvoke.GaussianBlur(fake12, fake12, new Size(9, 9), 1, 1);
            //    C1111vInvoke.GaussianBlur(fake12, fake12, new Size(9, 9), 1, 1);
            //            We don't need the _img. We are interested in only the otsu_thresh_val but unfortunately, currently there is no method in OpenCV which allows you to compute only the threshold value.

            //Use the Otsu's threshold value as higher threshold and half of the same as the lower threshold for Canny's algorithm.

            //double high_thresh_val1 = otsu_thresh_val1,
            //       lower_thresh_val1 = otsu_thresh_val1 * 0.5;



            //CvInvoke.GaussianBlur(warped, fake12, new Size(9, 9), 1, 1);
            CvInvoke.Canny(smoothedGrayFrame12, canny_output12, firstCannyThresh, secondCannyThresh);
            //                    CvInvoke.Canny(smoothedGrayFrame12, canny_output12, 120, 50);
            // CvInvoke.GaussianBlur(canny_output12, canny_output12, new Size(11, 11), 1, 1);
            //    CvInvoke.GaussianBlur(canny_output12, canny_output12, new Size(7, 7), 1, 1);

            // result.WarpedTargetCanny = canny_output12;//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
            //#######test
            #endregion test

            #endregion blur gray canny samej tarczy


            // result.SmOryCanny = smoothedGrayFrame12;

            #endregion  hocki klocki przepierdalanie obrazu


            //odpal manualne pozycjonowanie
            ManualShotPositioning msp = new ManualShotPositioning();
            msp.SetTargetAndShot(circleImage, czteryIpolmmR_int, useThisTarget);
            DialogResult dr = msp.ShowDialog();
            CvInvoke.Circle(circleImage, Point.Round(msp.SelectedPoint), czteryIpolmmR_int, new Bgr(Color.DeepPink).MCvScalar, 1, LineType.AntiAlias, 0);
            result.Shot = WyliczWartoscPrzestrzeliny(msp.SelectedPoint, useThisTarget);
            DrawCircles(circleImage, pix, useThisTarget.BlackCenter);
            result.TargetScanWithResult = circleImage;//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

            return(result);
        }
Пример #6
0
        public Final(TargetDetails settings)
        {
            InitializeComponent();
            bidaSiusSettings = settings;
            Shots.Add(new Shot {
                No = 1, Value = 10.9, Time = DateTime.Now.Ticks, PointFromCenter = new Point {
                    X = 5, Y = 5
                }
            });
            Shots.Add(new Shot {
                No = 1, Value = 10.5, Time = DateTime.Now.Ticks + 1, PointFromCenter = new Point {
                    X = 15, Y = 15
                }
            });
            Shots.Add(new Shot {
                No = 1, Value = 9.9, Time = DateTime.Now.Ticks + 2, PointFromCenter = new Point {
                    X = 21, Y = 35
                }
            });
            Shots.Add(new Shot {
                No = 1, Value = 8.9, Time = DateTime.Now.Ticks + 3, PointFromCenter = new Point {
                    X = 28, Y = 35
                }
            });
            Shots.Add(new Shot {
                No = 1, Value = 10.1, Time = DateTime.Now.Ticks + 4, PointFromCenter = new Point {
                    X = 27, Y = 25
                }
            });
            Shots.Add(new Shot {
                No = 1, Value = 10.2, Time = DateTime.Now.Ticks + 5, PointFromCenter = new Point {
                    X = 22, Y = 23
                }
            });
            Shots.Add(new Shot {
                No = 1, Value = 10.4, Time = DateTime.Now.Ticks + 6, PointFromCenter = new Point {
                    X = 34, Y = 11
                }
            });
            Shots.Add(new Shot {
                No = 1, Value = 10.2, Time = DateTime.Now.Ticks + 7, PointFromCenter = new Point {
                    X = 45, Y = 66
                }
            });
            Shots.Add(new Shot {
                No = 1, Value = 7, Time = DateTime.Now.Ticks + 8, PointFromCenter = new Point {
                    X = 21, Y = 34
                }
            });
            Shots.Add(new Shot {
                No = 1, Value = 8, Time = DateTime.Now.Ticks + 9, PointFromCenter = new Point {
                    X = 20, Y = 55
                }
            });
            Shots.Add(new Shot {
                No = 1, Value = 9.7, Time = DateTime.Now.Ticks + 10, PointFromCenter = new Point {
                    X = 10, Y = 32
                }
            });

            Shots.Add(new Shot {
                No = 1, Value = 10.5, Time = DateTime.Now.Ticks + 11, PointFromCenter = new Point {
                    X = 15, Y = 15
                }
            });
            Shots.Add(new Shot {
                No = 1, Value = 9.9, Time = DateTime.Now.Ticks + 21, PointFromCenter = new Point {
                    X = 21, Y = 35
                }
            });
            Shots.Add(new Shot {
                No = 1, Value = 8.9, Time = DateTime.Now.Ticks + 32, PointFromCenter = new Point {
                    X = 28, Y = 35
                }
            });
            Shots.Add(new Shot {
                No = 1, Value = 10.1, Time = DateTime.Now.Ticks + 34, PointFromCenter = new Point {
                    X = 27, Y = 25
                }
            });
            Shots.Add(new Shot {
                No = 1, Value = 10.2, Time = DateTime.Now.Ticks + 45, PointFromCenter = new Point {
                    X = 22, Y = 23
                }
            });
            Shots.Add(new Shot {
                No = 1, Value = 10.4, Time = DateTime.Now.Ticks + 56, PointFromCenter = new Point {
                    X = 34, Y = 11
                }
            });
            Shots.Add(new Shot {
                No = 1, Value = 10.2, Time = DateTime.Now.Ticks + 67, PointFromCenter = new Point {
                    X = 45, Y = 66
                }
            });
            Shots.Add(new Shot {
                No = 1, Value = 7, Time = DateTime.Now.Ticks + 58, PointFromCenter = new Point {
                    X = 21, Y = 34
                }
            });
            Shots.Add(new Shot {
                No = 1, Value = 8, Time = DateTime.Now.Ticks + 95, PointFromCenter = new Point {
                    X = 20, Y = 55
                }
            });
            Shots.Add(new Shot {
                No = 1, Value = 9.7, Time = DateTime.Now.Ticks + 510, PointFromCenter = new Point {
                    X = 10, Y = 32
                }
            });

            Shots.Add(new Shot {
                No = 1, Value = 10.5, Time = DateTime.Now.Ticks + 61, PointFromCenter = new Point {
                    X = 15, Y = 15
                }
            });
            Shots.Add(new Shot {
                No = 1, Value = 9.9, Time = DateTime.Now.Ticks + 27, PointFromCenter = new Point {
                    X = 21, Y = 35
                }
            });
            Shots.Add(new Shot {
                No = 1, Value = 8.9, Time = DateTime.Now.Ticks + 38, PointFromCenter = new Point {
                    X = 28, Y = 35
                }
            });

            //   flPanelSeries.Controls.Add(new testUC());


            RefreshTarget();
        }