示例#1
0
        private void buttonRepairLast_Click(object sender, EventArgs e)
        {
            var last  = Shots.Last();
            Mat frame = new Mat();

            if (string.IsNullOrWhiteSpace(last.WarpedFileName))
            {
                return;
            }

            string filePath = bidaSiusSettings.ImagesFolderPath + last.WarpedFileName;

            if (!File.Exists(filePath))
            {
                return;
            }

            Image <Bgr, Byte> ff;

            using (ff = new Image <Bgr, byte>(filePath))//.Resize(400, 400, Emgu.CV.CvEnum.Inter.Linear, true);
            {
                frame = ff.Mat;
                int czteryIpolmmR_int = CaptureHelper.GetCzteryIpolmmR_int(bidaSiusSettings);

                //odpal manualne pozycjonowanie
                ManualShotPositioning msp = new ManualShotPositioning();
                msp.SetTargetAndShot(frame, czteryIpolmmR_int, bidaSiusSettings);
                DialogResult dr      = msp.ShowDialog();
                var          newShot = CaptureHelper.WyliczWartoscPrzestrzeliny(msp.SelectedPoint, bidaSiusSettings);
                last.Update(newShot);
                RefreshTarget();
            }
        }
示例#2
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);
        }