예제 #1
0
        public static Results <PointT> ProcessMostInliers <PointT>(IRansacModel <PointT> model, int maxIterations, int sampleSize, int minGoodPoints, double threshold, double initialModel)
        {
            Random        random      = new Random((int)DateTime.Now.Ticks);
            object        bestModel   = initialModel;
            List <PointT> bestInliers = new List <PointT>();

            for (int i = 0; i < maxIterations; ++i)
            {
                NextSample(model, sampleSize, threshold, random, out object sampleModel, out List <PointT> inliers);

                if (inliers.Count > bestInliers.Count)
                {
                    bestInliers = inliers;
                    bestModel   = sampleModel;
                }
            }

            double bestError = 0.0;

            foreach (var point in model.AllPoints)
            {
                bestError += model.PointError(point, bestModel);
            }

            return(new Results <PointT>()
            {
                BestModel = bestModel,
                BestError = bestError,
                Inliers = bestInliers
            });
        }
 public bool Test(IRansacModel model) {
   
   PlaneModel r = model as PlaneModel;
   bool no_parallel_found = true;
   foreach (Plane p in _b.ReferencePlanes) {
     double d = Vector.ScalarProduct(r.Plane.Normal, p.Normal);
     if ((1.0 - Math.Abs(d)) < 1e-2) {
       no_parallel_found = false;
       break;
     }
   }
   return no_parallel_found;
 }
예제 #3
0
        private static void NextSample <PointT>(IRansacModel <PointT> model, int sampleSize, double threshold, Random random, out object sampleModel, out List <PointT> inliers)
        {
            IEnumerable <PointT> sample = PickRandomSample(model.AllPoints, sampleSize, random);

            sampleModel = model.FindModel(sample);
            inliers     = new List <PointT>(model.AllPoints.Count);
            foreach (var point in model.AllPoints)
            {
                if (model.PointError(point, sampleModel) < threshold)
                {
                    inliers.Add(point);
                }
            }
        }
예제 #4
0
        public bool Test(IRansacModel model)
        {
            PlaneModel r = model as PlaneModel;
            bool       no_parallel_found = true;

            foreach (Plane p in _b.ReferencePlanes)
            {
                double d = Vector.ScalarProduct(r.Plane.Normal, p.Normal);
                if ((1.0 - Math.Abs(d)) < 1e-2)
                {
                    no_parallel_found = false;
                    break;
                }
            }
            return(no_parallel_found);
        }
예제 #5
0
        public static Results <PointT> Process <PointT>(IRansacModel <PointT> model, int maxIterations, int sampleSize, int minGoodPoints, double threshold, object initialModel)
        {
            Random random    = new Random((int)DateTime.Now.Ticks);
            object bestModel = initialModel;
            double bestError = 10e8;

            for (int i = 0; i < maxIterations; ++i)
            {
                NextSample(model, sampleSize, threshold, random, out object sampleModel, out List <PointT> inliers);

                if (bestModel == null || inliers.Count >= minGoodPoints)
                {
                    sampleModel = model.FindModel(inliers);
                    double error = 0.0;
                    foreach (var point in model.AllPoints)
                    {
                        error += model.PointError(point, sampleModel);
                    }

                    if (error < bestError)
                    {
                        bestError = error;
                        bestModel = sampleModel;
                    }
                }
            }

            var bestInliers = model.AllPoints
                              .Where((point) => model.PointError(point, bestModel) < threshold)
                              .ToList();

            return(new Results <PointT>()
            {
                BestModel = bestModel,
                BestError = bestError,
                Inliers = bestInliers
            });
        }