コード例 #1
0
        public void UseRansacAlgorithm(int iterationsCount = 1000, float r = 5, float R = 700, bool secondError = true)
        {
            var min = GetMinSide();

            r = min * 0.05f;
            R = min * 0.3f;
            RansacTriangle             = Ransac.RansacAlgorithm(ConsistencyNeighbourPairs, iterationsCount, r, R, secondError);
            RansacFilterNeighbourPairs = Ransac.RansacFilterKeyPoint(ConsistencyNeighbourPairs, RansacTriangle, R);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: skyterrae/P3RANSAC
    static void Main(string[] args)
    {
        RansacSettings = new Ransac[40];
        int IterateAmount = 700;

        //iterate through all settings
        for (int i = 0; i < RansacSettings.Length; i++)
        {
            int k;
            if (i < 20)
            {
                k = 500;
            }
            else
            {
                k = 1000;
            }
            int x, y;
            if ((i % 20) < 5)
            {
                x = 600; y = 600;
            }
            else if ((i % 20) < 10)
            {
                x = 900; y = 400;
            }
            else if ((i % 20) < 15)
            {
                x = 1200; y = 300;
            }
            else
            {
                x = 1500; y = 240;
            }
            int b = i % 5;

            Console.WriteLine(System.DateTime.Now + " - Setting " + i + ", k=" + k + ", b=" + b + ", x=" + x + ", y=" + y);
            RansacSettings[i] = new Ransac(k, b, x, y, IterateAmount);
            RansacSettings[i].WriteToFile("output" + i + ".txt");
            Console.WriteLine(System.DateTime.Now + " - Setting " + i + ", " + RansacSettings[i].ToString());
        }
        Console.WriteLine(System.DateTime.Now + " - Mission Accompished.");

        Console.ReadLine();
    }
コード例 #3
0
        private void FindPairs()
        {
            ChangeButtonState();
            Pairs = new List <Pair>();
            foreach (var p in Pic1Points)
            {
                var pair = KeyPointService.FindPair(p, Pic2Points);
                if (p.Equals(KeyPointService.FindPair(pair, Pic1Points)))
                {
                    Pairs.Add(new Pair()
                    {
                        A = p,
                        B = pair,
                    });
                }
            }

            if (Pairs.Count < Neighbors)
            {
                Neighbors = Pairs.Count;
            }

            Application.Current.Dispatcher.Invoke((Action) delegate { PairsTextBox.Text = Pairs.Count.ToString(); });
            Ransac.FindBestModel(Pairs, Iterations, MaxError, Type);
            Pairs = Pairs.OrderByDescending(x => x.TransformationScore).ToList();

            int counter = 0;

            foreach (var p in Pairs)
            {
                counter++;
                KeyPointService.UpdatePairProperties(p, Pairs, Neighbors);
                DrawLine(p);
                UpdateProgressBar(counter, Pairs.Count);
            }
            ChangeButtonState();
        }
コード例 #4
0
        private void button2_Click(object sender, EventArgs e)
        {
            int maxPoints = Convert.ToInt32(txb_Filter.Text);

            string name = PathToWriteImage + "resultPicture.jpg";

            Bitmap bmp1 = new Bitmap(PathToReadImage + "bridge1.jpg");
            Bitmap bmp2 = new Bitmap(PathToReadImage + "bridge2.jpg");

            var descriptorsABlobs = BlobsFinder.FindBlobs(IOHelper.ImageToMat(bmp1), maxPoints);
            var descriptorsBBlobs = BlobsFinder.FindBlobs(IOHelper.ImageToMat(bmp2), maxPoints);
            var match             = DescriptorMatcher.Nndr(descriptorsABlobs, descriptorsBBlobs);

            lbl_findPoints1.Text = "Найдено интересных точек(1): " + descriptorsABlobs.Count;
            lbl_findPoints2.Text = "Найдено интересных точек(2): " + descriptorsBBlobs.Count;
            lbl_PairCount.Text   = "Найдено пар точек: " + match.Count;

            var(matrixA, matrixB) = Ransac.CalculateTransform(match);
            var result = Transformer.Transform(bmp1, bmp2, matrixA, matrixB);

            result.Save(name, ImageFormat.Jpeg);

            pictureBox1.Image = result;
        }
コード例 #5
0
        public void Approximate(int topIndention, double sampleShare, double outlierShare, int iterations)
        {
            Ransac          linear     = new Ransac(sampleShare, outlierShare, iterations);
            List <IntPoint> leftPoints = new List <IntPoint>();

            LeftContour.Points.ForEach(point =>
            {
                if (point.Y >= topIndention)
                {
                    leftPoints.Add(point);
                }
            });
            List <IntPoint> rightPoints = new List <IntPoint>();

            RightContour.Points.ForEach(point =>
            {
                if (point.Y >= topIndention)
                {
                    rightPoints.Add(point);
                }
            });
            _leftApproximation  = linear.Approximate(leftPoints, leftPoints.Count, out _rSquareLeft, out _relativeEstimationLeft);
            _rightApproximation = linear.Approximate(rightPoints, rightPoints.Count, out _rSquareRight, out _relativeEstimationRight);
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: Kulawy/PictureAnalysisApp
        static void Main(string[] args)
        {
            Stopwatch st = new Stopwatch();

            #region Develop
            ImageUtils        imgUtils  = new ImageUtils();
            KeyPointExtractor myExtrac  = new KeyPointExtractor();
            ExtractionManager exManager = new ExtractionManager();
            myExtrac.ExtractKeyPoints(Const.imagesFolderDirectory + Const.imgName01 + ".png");
            myExtrac.ExtractKeyPoints(Const.imagesFolderDirectory + Const.imgName02 + ".png");
            PictureKeyPoints pkp01 = new PictureKeyPoints(Const.imgName01);
            PictureKeyPoints pkp02 = new PictureKeyPoints(Const.imgName02);
            LetDraw          ld    = new LetDraw();

            pkp01.KeyPoints = exManager.ExtractKeyPointsFromImages(pkp01.GetImagePath());
            pkp02.KeyPoints = exManager.ExtractKeyPointsFromImages(pkp02.GetImagePath());

            KeyPointPairsFinder kppf = new KeyPointPairsFinder(pkp01, pkp02);

            //foreach (KeyPoint kp in pkp01.KeyPoints)
            //{
            //    Console.WriteLine("Picture One key points: \n");
            //    Console.WriteLine(kp);
            //}

            Console.WriteLine("Start searching neighbours");
            st.Start();
            //Dictionary<KeyPoint, KeyPoint> neighbors = exManager.FindNeighbers(pkp01.KeyPoints, pkp02.KeyPoints); //WHY DICTIONARY NOT WORK ?
            List <KeyValuePair <KeyPoint, KeyPoint> > neighbors = kppf.FindKeyPointsPairs();
            st.Stop();
            Console.WriteLine("Neighbors Count: " + neighbors.Count + "\nin time: " + st.ElapsedMilliseconds.ToString());
            //ld.MergeImagesAndDrawLines(neighbors);


            /*
             * st.Reset();
             * st.Start();
             * NeighbourhoodCoherenceFilter neighbourhoodCoherenceFilter = new NeighbourhoodCoherenceFilter(neighbors, Const.neighborsToCheck, Const.neighborsCondition);
             * List<KeyValuePair<KeyPoint, KeyPoint>> filteredPairs = neighbourhoodCoherenceFilter.GetFilteredPairs();
             * st.Stop();
             * Console.WriteLine("AFTER FILTER");
             * Console.WriteLine("pairs Count: " + filteredPairs.Count + "\nin time: " + st.ElapsedMilliseconds.ToString());
             * //ld.MergeImagesAndDrawLines(filteredPairs);
             */

            Console.WriteLine("RANSAC IN PROGRESS");
            st.Reset();
            st.Start();
            //ITransform transform = new AffineTransform();
            ITransform      transform       = new PerspectiveTransform();
            Ransac          ransac          = new Ransac(Const.iterationNumber, transform, Const.maxError);
            TransformFilter transformFilter = new TransformFilter(ransac);
            List <KeyValuePair <KeyPoint, KeyPoint> > ransacPairs = transformFilter.Filter(neighbors);
            st.Stop();
            Console.WriteLine("AFTER RANSCAC");
            Console.WriteLine("pairs Count: " + ransacPairs.Count + "\nin time: " + st.ElapsedMilliseconds.ToString());

            ld.MergeImagesAndDrawLines(ransacPairs);



            Console.ReadKey();

            #endregion

            //ConsoleInterface cI = new ConsoleInterface();
        }
コード例 #7
0
ファイル: PlaneRansac.cs プロジェクト: guozanhua/parsley
    /// <summary>
    /// Find laser-plane through RANSAC
    /// </summary>
    /// <param name="context">Context</param>
    /// <param name="plane">Found plane</param>
    /// <returns>Success</returns>
    public bool FindLaserPlane(Bundle bundle) {
      BundleBookmarks b = new BundleBookmarks(bundle);

      List<System.Drawing.PointF> laser_pixels = b.LaserPixel;
      List<Ray> eye_rays = b.EyeRays;
      System.Drawing.Rectangle roi = b.ROI;

      List<Ray> rays;
      if (_only_out_of_roi) {
        rays = new List<Ray>();
        for (int i = 0; i < laser_pixels.Count; ++i) {
          if (!roi.Contains(laser_pixels[i])) {
            rays.Add(eye_rays[i]);
          }
        }
      } else {
        rays = eye_rays;
      }

      if (rays.Count == 0) {
        return false;
      }

      Vector[] isect;
      double[] ts;
      int[] plane_ids;

      IList<Plane> reference_planes = b.ReferencePlanes;
      Core.Intersection.FindEyeRayPlaneIntersections(
        rays.ToArray(), 
        reference_planes.ToArray(), 
        out ts, out isect, out plane_ids);

      Ransac<PlaneModel> ransac = new Ransac<PlaneModel>(isect);
      int min_consensus = (int)Math.Max(rays.Count * _min_consensus_precent, b.Image.Width * 0.05);
      _constraint.Bundle = bundle;
      Ransac<PlaneModel>.Hypothesis h = ransac.Run(_max_iterations, _plane_accurracy, min_consensus, _constraint);

      if (h != null) {
        b.LaserPlane = h.Model.Plane;
        return true;
      } else {
        return false;
      }
    }