use of boofcv.abst.geo.Estimate1ofEpipolar in project BoofCV by lessthanoptimal.
the class TestRemovePerspectiveDistortion method applyForwardTransform.
private void applyForwardTransform(GrayF32 expected, GrayF32 input, Point2D_F64 topLeft, Point2D_F64 topRight, Point2D_F64 bottomRight, Point2D_F64 bottomLeft) {
Estimate1ofEpipolar computeHomography = FactoryMultiView.computeHomographyDLT(true);
ArrayList<AssociatedPair> associatedPairs = new ArrayList<>();
associatedPairs.add(new AssociatedPair(topLeft, new Point2D_F64(0, 0)));
associatedPairs.add(new AssociatedPair(topRight, new Point2D_F64(expected.width - 1, 0)));
associatedPairs.add(new AssociatedPair(bottomRight, new Point2D_F64(expected.width - 1, expected.height - 1)));
associatedPairs.add(new AssociatedPair(bottomLeft, new Point2D_F64(0, expected.height - 1)));
DMatrixRMaj H = new DMatrixRMaj(3, 3);
computeHomography.process(associatedPairs, H);
FMatrixRMaj H32 = new FMatrixRMaj(3, 3);
ConvertMatrixData.convert(H, H32);
new FDistort(expected, input).transform(new PointTransformHomography_F32(H32)).apply();
}
use of boofcv.abst.geo.Estimate1ofEpipolar in project BoofCV by lessthanoptimal.
the class BenchmarkStabilityFundamental method evaluateMinimal.
public void evaluateMinimal(GeoModelEstimatorN<DMatrixRMaj, AssociatedPair> estimatorN) {
DistanceEpipolarConstraint distance = new DistanceEpipolarConstraint();
Estimate1ofEpipolar estimator = new EstimateNto1ofEpipolar(estimatorN, distance, 1);
scores = new ArrayList<>();
int failed = 0;
int numSamples = estimator.getMinimumPoints();
Random rand = new Random(234);
DMatrixRMaj F = new DMatrixRMaj(3, 3);
for (int i = 0; i < 50; i++) {
List<AssociatedPair> pairs = new ArrayList<>();
// create a unique set of pairs
while (pairs.size() < numSamples) {
AssociatedPair p = observations.get(rand.nextInt(observations.size()));
if (!pairs.contains(p)) {
pairs.add(p);
}
}
if (!estimator.process(pairs, F)) {
failed++;
continue;
}
// normalize the scale of F
CommonOps_DDRM.scale(1.0 / CommonOps_DDRM.elementMaxAbs(F), F);
double totalScore = 0;
// score against all observations
for (AssociatedPair p : observations) {
double score = Math.abs(GeometryMath_F64.innerProd(p.p2, F, p.p1));
if (Double.isNaN(score))
System.out.println("Score is NaN");
scores.add(score);
totalScore += score;
}
// System.out.println(" score["+i+"] = "+totalScore);
}
Collections.sort(scores);
System.out.printf(" Failures %3d Score: 50%% = %6.3e 95%% = %6.3e\n", failed, scores.get(scores.size() / 2), scores.get((int) (scores.size() * 0.95)));
}
use of boofcv.abst.geo.Estimate1ofEpipolar in project BoofCV by lessthanoptimal.
the class ExampleFundamentalMatrix method robustFundamental.
/**
* Given a set of noisy observations, compute the Fundamental matrix while removing
* the noise.
*
* @param matches List of associated features between the two images
* @param inliers List of feature pairs that were determined to not be noise.
* @return The found fundamental matrix.
*/
public static DMatrixRMaj robustFundamental(List<AssociatedPair> matches, List<AssociatedPair> inliers) {
// used to create and copy new instances of the fit model
ModelManager<DMatrixRMaj> managerF = new ModelManagerEpipolarMatrix();
// Select which linear algorithm is to be used. Try playing with the number of remove ambiguity points
Estimate1ofEpipolar estimateF = FactoryMultiView.computeFundamental_1(EnumFundamental.LINEAR_7, 2);
// Wrapper so that this estimator can be used by the robust estimator
GenerateEpipolarMatrix generateF = new GenerateEpipolarMatrix(estimateF);
// How the error is measured
DistanceFromModelResidual<DMatrixRMaj, AssociatedPair> errorMetric = new DistanceFromModelResidual<>(new FundamentalResidualSampson());
// Use RANSAC to estimate the Fundamental matrix
ModelMatcher<DMatrixRMaj, AssociatedPair> robustF = new Ransac<>(123123, managerF, generateF, errorMetric, 6000, 0.1);
// Estimate the fundamental matrix while removing outliers
if (!robustF.process(matches))
throw new IllegalArgumentException("Failed");
// save the set of features that were used to compute the fundamental matrix
inliers.addAll(robustF.getMatchSet());
// Improve the estimate of the fundamental matrix using non-linear optimization
DMatrixRMaj F = new DMatrixRMaj(3, 3);
ModelFitter<DMatrixRMaj, AssociatedPair> refine = FactoryMultiView.refineFundamental(1e-8, 400, EpipolarError.SAMPSON);
if (!refine.fitModel(inliers, robustF.getModelParameters(), F))
throw new IllegalArgumentException("Failed");
// Return the solution
return F;
}
use of boofcv.abst.geo.Estimate1ofEpipolar in project BoofCV by lessthanoptimal.
the class TestBaseDetectFiducialSquare method render.
/**
* Draws a distorted pattern onto the output
*/
public static void render(GrayU8 pattern, Quadrilateral_F64 where, GrayU8 output) {
int w = pattern.width;
int h = pattern.height;
ArrayList<AssociatedPair> associatedPairs = new ArrayList<>();
associatedPairs.add(new AssociatedPair(where.a, new Point2D_F64(0, 0)));
associatedPairs.add(new AssociatedPair(where.b, new Point2D_F64(w, 0)));
associatedPairs.add(new AssociatedPair(where.c, new Point2D_F64(w, h)));
associatedPairs.add(new AssociatedPair(where.d, new Point2D_F64(0, h)));
Estimate1ofEpipolar computeHomography = FactoryMultiView.computeHomographyDLT(true);
DMatrixRMaj H = new DMatrixRMaj(3, 3);
computeHomography.process(associatedPairs, H);
// Create the transform for distorting the image
FMatrixRMaj H32 = new FMatrixRMaj(3, 3);
ConvertMatrixData.convert(H, H32);
PointTransformHomography_F32 homography = new PointTransformHomography_F32(H32);
PixelTransform2_F32 pixelTransform = new PointToPixelTransform_F32(homography);
// Apply distortion and show the results
DistortImageOps.distortSingle(pattern, output, pixelTransform, InterpolationType.BILINEAR, BorderType.SKIP);
// ShowImages.showWindow(output, "Rendered");
// try {Thread.sleep(10000);} catch (InterruptedException e) {}
}
use of boofcv.abst.geo.Estimate1ofEpipolar in project BoofCV by lessthanoptimal.
the class BenchmarkRuntimeRefineHomography method runAll.
public void runAll() {
System.out.println("========= Profile numFeatures " + NUM_POINTS);
System.out.println();
double tol = 1e-16;
int MAX_ITER = 200;
init(NUM_POINTS, PIXELS, true);
Estimate1ofEpipolar computeAlg = FactoryMultiView.computeHomographyDLT(true);
computeAlg.process(pairs, H);
H.data[0] += 0.1;
H.data[4] -= 0.15;
H.data[7] -= 0.2;
ProfileOperation.printOpsPerSec(new Refine("Simple", refineHomography(tol, MAX_ITER, EpipolarError.SIMPLE)), TEST_TIME);
ProfileOperation.printOpsPerSec(new Refine("Sampson", refineHomography(tol, MAX_ITER, EpipolarError.SAMPSON)), TEST_TIME);
ProfileOperation.printOpsPerSec(new Linear4(), TEST_TIME);
System.out.println();
System.out.println("Done");
}
Aggregations