public void getInliers( List<Point2D_F64> left , List<Point2D_F64> right , List<Point2D_F64> inliersLeft , List<Point2D_F64> inliersRight ) { int N = robustH.getMatchSet().size(); for( int i = 0; i < N; i++ ) { int index = robustH.getInputIndex(i); inliersLeft.add( left.get(index) ); inliersRight.add( right.get(index) ); } }
@Override public boolean process(List<Point> dataSet) { return mm.process(dataSet); }
@Override public double getFitQuality() { return mm.getFitQuality(); }
/** * Searches for lines inside inside the region.. * * @param gridLines Where the found lines are stored. */ private void findLinesInRegion( List<LineSegment2D_F32> gridLines ) { List<Edgel> list = edgels.copyIntoList(null); int iterations = 0; // exit if not enough points or max iterations exceeded while( iterations++ < maxDetectLines) { if( !robustMatcher.process(list) ) break; // remove the found edges from the main list List<Edgel> matchSet = robustMatcher.getMatchSet(); // make sure the match set is large enough if( matchSet.size() < minInlierSize ) break; for( Edgel e : matchSet ) { list.remove(e); } gridLines.add(convertToLineSegment(matchSet, robustMatcher.getModelParameters())); } }
/** * Make sure the function getInputIndex() returns the original index */ @Test public void checkMatchSetToInputIndex() { double mean = 2.5; double tol = 0.2; // generate the points with a smaller tolerance to account for fitting error // later on. ModelMatcher<double[],Double> alg = createModel(4, tol * 0.95); List<Double> samples = createSampleSet(100, mean, tol, 0.1); assertTrue(alg.process(samples)); List<Double> matchSet = alg.getMatchSet(); // sanity check to make sure there is a large enough match set assertTrue(matchSet.size() > 20); int orderNotTheSame = 0; for( int i = 0; i < matchSet.size(); i++ ) { int expected = samples.indexOf(matchSet.get(i)); int found = alg.getInputIndex(i); if( found != i ) orderNotTheSame++; assertEquals(expected, found); } // sanity check to make sure the order has been changed assertTrue(orderNotTheSame != matchSet.size()); }
/** * Estimate the plane's normal and the distance from the plane. From the set of matched pairs a homography * is estimated. The homography is then decomposed to find the camera baseline and a description of the plane. * The decomposition generates several hypotheses, but only the one which is the best match to the known camera * baseline is used. */ private boolean estimatePlane(List<AssociatedPair> matches) { // RANSAC to find best homography if( !robustH.process(matches) ) return false; DenseMatrix64F Hd = UtilHomography.convert(robustH.getModelParameters(), (DenseMatrix64F) null); selectBest.process(Hd,true); return true; }
@Override public List<Point> getMatchSet() { return mm.getMatchSet(); }
@Override public int getInputIndex(int matchIndex) { return mm.getInputIndex(matchIndex); }
if( !motion.process(obs) ) throw new RuntimeException("Failed ransac"); System.out.println("inlier size "+motion.getMatchSet().size()); Se3_F64 camToWorld = motion.getModelParameters(); Se3_F64 worldToCam = motion.getModelParameters().invert(null);
if( !motion.process(obs) ) throw new RuntimeException("Failed ransac"); System.out.println("inlier size "+motion.getMatchSet().size()); Se3_F64 camToWorld = motion.getModelParameters(); Se3_F64 worldToCam = motion.getModelParameters().invert(null);
/** * Save a list of inliers in pixel coordinates */ private void createInliersList( ModelMatcher<Se3_F64, AssociatedPair> epipolarMotion ) { inliersPixel = new ArrayList<>(); FastQueue<AssociatedIndex> matches = associate.getMatches(); int N = epipolarMotion.getMatchSet().size(); for( int i = 0; i < N; i++ ) { AssociatedIndex a = matches.get( epipolarMotion.getInputIndex(i)); Point2D_F64 p1 = locationSrc.get( a.src ); Point2D_F64 p2 = locationDst.get( a.dst ); inliersPixel.add( new AssociatedPair(p1,p2)); } }
if( !motion.process(obs) ) throw new RuntimeException("Failed ransac"); System.out.println("inlier size "+motion.getMatchSet().size()); Se3_F64 camToWorld = motion.getModelParameters(); Se3_F64 worldToCam = motion.getModelParameters().invert(null);
public static void main( String args[] ) { Random rand = new Random(234); //------------------------ Create Observations // define a line in 2D space as the tangent from the origin double lineX = -2.1; double lineY = 1.3; List<Point2D> points = generateObservations(rand, lineX, lineY); //------------------------ Compute the solution // Let it know how to compute the model and fit errors ModelManager<Line2D> manager = new LineManager(); ModelGenerator<Line2D,Point2D> generator = new LineGenerator(); DistanceFromModel<Line2D,Point2D> distance = new DistanceFromLine(); // RANSAC or LMedS work well here ModelMatcher<Line2D,Point2D> alg = new Ransac<>(234234, manager, generator, distance, 500, 0.01); // ModelMatcher<Line2D,Point2D> alg = // new LeastMedianOfSquares<Line2D, Point2D>(234234,100,0.1,0.5,generator,distance); if( !alg.process(points) ) throw new RuntimeException("Robust fit failed!"); // let's look at the results Line2D found = alg.getModelParameters(); // notice how all the noisy points were removed and an accurate line was estimated? System.out.println("Found line "+found); System.out.println("Actual line x = "+lineX+" y = "+lineY); System.out.println("Match set size = "+alg.getMatchSet().size()); }
/** * Sees if it can correctly select a model set and determine the best fit parameters for * a simple test case. */ @Test public void performSimpleModelFit() { double mean = 2.5; double tol = 0.2; // generate the points with a smaller tolerance to account for fitting error // later on. ModelMatcher<double[],Double> alg = createModel(4, tol * 0.95); List<Double> samples = createSampleSet(100, mean, tol, 0.1); assertTrue(alg.process(samples)); List<Double> matchSet = alg.getMatchSet(); if (checkInlierSet) assertTrue(matchSet.size() / 90.0 >= minMatchFrac); assertEquals(inlierMean, alg.getModelParameters()[0], parameterTol); }
/** * Multiple data sets are processed in an attempt to see if it is properly reinitializing * itself and returns the correct solutions. */ @Test public void runMultipleTimes() { double mean = 2.5; double tol = 0.2; // generate the points with a smaller tolerance to account for fitting error // later on. ModelMatcher<double[],Double> alg = createModel(4, tol); for (int i = 0; i < 10; i++) { // try different sample sizes in each trial. a bug was found once where // a small value of N than previous caused a problem int N = 200 - i * 10; List<Double> samples = createSampleSet(N, mean, tol * 0.90, 0.1); assertTrue(alg.process(samples)); List<Double> matchSet = alg.getMatchSet(); double foundMean = alg.getModelParameters()[0]; if (checkInlierSet) assertTrue(matchSet.size() / (N * 0.9) >= minMatchFrac); assertEquals(inlierMean, foundMean, parameterTol); } }