use of boofcv.struct.geo.AssociatedPair in project BoofCV by lessthanoptimal.
the class BenchmarkStabilityFundamental method evaluateAll.
public void evaluateAll(GeoModelEstimator1<DMatrixRMaj, AssociatedPair> estimator) {
scores = new ArrayList<>();
int failed = 0;
DMatrixRMaj F = new DMatrixRMaj(3, 3);
for (int i = 0; i < 50; i++) {
if (!estimator.process(observations, F)) {
failed++;
continue;
}
// normalize the scale of F
CommonOps_DDRM.scale(1.0 / CommonOps_DDRM.elementMaxAbs(F), F);
// 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);
}
}
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.struct.geo.AssociatedPair in project BoofCV by lessthanoptimal.
the class EssentialNister5 method computeSpan.
/**
* From the epipolar constraint p2^T*E*p1 = 0 construct a linear system
* and find its null space.
*/
private void computeSpan(List<AssociatedPair> points) {
Q.reshape(points.size(), 9);
int index = 0;
for (int i = 0; i < points.size(); i++) {
AssociatedPair p = points.get(i);
Point2D_F64 a = p.p2;
Point2D_F64 b = p.p1;
// The points are assumed to be in homogeneous coordinates. This means z = 1
Q.data[index++] = a.x * b.x;
Q.data[index++] = a.x * b.y;
Q.data[index++] = a.x;
Q.data[index++] = a.y * b.x;
Q.data[index++] = a.y * b.y;
Q.data[index++] = a.y;
Q.data[index++] = b.x;
Q.data[index++] = b.y;
Q.data[index++] = 1;
}
if (!solverNull.process(Q, 4, nullspace))
throw new RuntimeException("Nullspace solver should never fail, probably bad input");
// extract the span of solutions for E from the null space
for (int i = 0; i < 9; i++) {
X[i] = nullspace.unsafe_get(i, 0);
Y[i] = nullspace.unsafe_get(i, 1);
Z[i] = nullspace.unsafe_get(i, 2);
W[i] = nullspace.unsafe_get(i, 3);
}
}
use of boofcv.struct.geo.AssociatedPair in project BoofCV by lessthanoptimal.
the class LowLevelMultiViewOps method applyNormalization.
public static void applyNormalization(List<AssociatedPair> points, NormalizationPoint2D N1, NormalizationPoint2D N2, DMatrix1Row X1, DMatrixRMaj X2) {
final int size = points.size();
X1.reshape(size, 2);
X2.reshape(size, 2);
for (int i = 0, index = 0; i < size; i++, index += 2) {
AssociatedPair pair = points.get(i);
X1.data[index] = (pair.p1.x - N1.meanX) / N1.stdX;
X1.data[index + 1] = (pair.p1.y - N1.meanY) / N1.stdY;
X2.data[index] = (pair.p2.x - N2.meanX) / N2.stdX;
X2.data[index + 1] = (pair.p2.y - N2.meanY) / N2.stdY;
}
}
use of boofcv.struct.geo.AssociatedPair 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.struct.geo.AssociatedPair in project BoofCV by lessthanoptimal.
the class ExampleFundamentalMatrix method main.
public static void main(String[] args) {
String dir = UtilIO.pathExample("structure/");
BufferedImage imageA = UtilImageIO.loadImage(dir, "undist_cyto_01.jpg");
BufferedImage imageB = UtilImageIO.loadImage(dir, "undist_cyto_02.jpg");
List<AssociatedPair> matches = computeMatches(imageA, imageB);
// Where the fundamental matrix is stored
DMatrixRMaj F;
// List of matches that matched the model
List<AssociatedPair> inliers = new ArrayList<>();
// estimate and print the results using a robust and simple estimator
// The results should be difference since there are many false associations in the simple model
// Also note that the fundamental matrix is only defined up to a scale factor.
F = robustFundamental(matches, inliers);
System.out.println("Robust");
F.print();
F = simpleFundamental(matches);
System.out.println("Simple");
F.print();
// display the inlier matches found using the robust estimator
AssociationPanel panel = new AssociationPanel(20);
panel.setAssociation(inliers);
panel.setImages(imageA, imageB);
ShowImages.showWindow(panel, "Inlier Pairs");
}
Aggregations