use of boofcv.struct.geo.AssociatedPair in project BoofCV by lessthanoptimal.
the class GenerateAffine2D method fitModel.
@Override
public boolean fitModel(List<AssociatedPair> dataSet, Affine2D_F64 initial, Affine2D_F64 found) {
from.clear();
to.clear();
for (int i = 0; i < dataSet.size(); i++) {
AssociatedPair p = dataSet.get(i);
from.add(p.p1);
to.add(p.p2);
}
if (!fitter.process(from, to))
return false;
found.set(fitter.getTransformSrcToDst());
return true;
}
use of boofcv.struct.geo.AssociatedPair in project BoofCV by lessthanoptimal.
the class Se3FromEssentialGenerator method generate.
/**
* Computes the camera motion from the set of observations. The motion is from the first
* into the second camera frame.
*
* @param dataSet Associated pairs in normalized camera coordinates.
* @param model The best pose according to the positive depth constraint.
*/
@Override
public boolean generate(List<AssociatedPair> dataSet, Se3_F64 model) {
if (!computeEssential.process(dataSet, E))
return false;
// extract the possible motions
decomposeE.decompose(E);
List<Se3_F64> candidates = decomposeE.getSolutions();
// use positive depth constraint to select the best one
Se3_F64 bestModel = null;
int bestCount = -1;
for (int i = 0; i < candidates.size(); i++) {
Se3_F64 s = candidates.get(i);
int count = 0;
for (AssociatedPair p : dataSet) {
if (depthCheck.checkConstraint(p.p1, p.p2, s)) {
count++;
}
}
if (count > bestCount) {
bestCount = count;
bestModel = s;
}
}
model.set(bestModel);
return true;
}
use of boofcv.struct.geo.AssociatedPair in project BoofCV by lessthanoptimal.
the class FactoryMultiViewRobust method epipolarRansac.
private static Ransac<Se3_F64, AssociatedPair> epipolarRansac(Estimate1ofEpipolar epipolar, CameraPinholeRadial intrinsic, ConfigRansac ransac) {
TriangulateTwoViewsCalibrated triangulate = FactoryMultiView.triangulateTwoGeometric();
ModelManager<Se3_F64> manager = new ModelManagerSe3_F64();
ModelGenerator<Se3_F64, AssociatedPair> generateEpipolarMotion = new Se3FromEssentialGenerator(epipolar, triangulate);
DistanceFromModel<Se3_F64, AssociatedPair> distanceSe3 = new DistanceSe3SymmetricSq(triangulate, intrinsic.fx, intrinsic.fy, intrinsic.skew, intrinsic.fx, intrinsic.fy, intrinsic.skew);
double ransacTOL = ransac.inlierThreshold * ransac.inlierThreshold * 2.0;
return new Ransac<>(ransac.randSeed, manager, generateEpipolarMotion, distanceSe3, ransac.maxIterations, ransacTOL);
}
use of boofcv.struct.geo.AssociatedPair in project BoofCV by lessthanoptimal.
the class FactoryMultiViewRobust method homographyLMedS.
/**
* Robust solution for estimating {@link Homography2D_F64} with {@link LeastMedianOfSquares LMedS}. Input
* observations are in pixel coordinates.
*
* <ul>
* <li>Four point linear is used internally</p>
* <li>inlierThreshold is in pixels</p>
* </ul>
*
* <p>See code for all the details.</p>
*
* @param homography Homography estimation parameters. If null default is used.
* @param configLMedS Parameters for LMedS. Can't be null.
* @return Homography estimator
*/
public static LeastMedianOfSquares<Homography2D_F64, AssociatedPair> homographyLMedS(ConfigHomography homography, ConfigLMedS configLMedS) {
if (homography == null)
homography = new ConfigHomography();
ModelManager<Homography2D_F64> manager = new ModelManagerHomography2D_F64();
GenerateHomographyLinear modelFitter = new GenerateHomographyLinear(homography.normalize);
DistanceHomographySq distance = new DistanceHomographySq();
LeastMedianOfSquares<Homography2D_F64, AssociatedPair> lmeds = new LeastMedianOfSquares<>(configLMedS.randSeed, configLMedS.totalCycles, manager, modelFitter, distance);
lmeds.setErrorFraction(configLMedS.errorFraction);
return lmeds;
}
use of boofcv.struct.geo.AssociatedPair in project BoofCV by lessthanoptimal.
the class HomographyDirectLinearTransform method createANormalized.
/**
* Compute the 'A' matrix used to solve for H from normalized points.
*/
protected void createANormalized(List<AssociatedPair> points, DMatrixRMaj A) {
A.reshape(points.size() * 2, 9, false);
A.zero();
Point2D_F64 f_norm = new Point2D_F64();
Point2D_F64 s_norm = new Point2D_F64();
final int size = points.size();
for (int i = 0; i < size; i++) {
AssociatedPair p = points.get(i);
// the first image
Point2D_F64 f = p.p1;
// the second image
Point2D_F64 s = p.p2;
// normalize the points
N1.apply(f, f_norm);
N2.apply(s, s_norm);
A.set(i * 2, 3, -f_norm.x);
A.set(i * 2, 4, -f_norm.y);
A.set(i * 2, 5, -1);
A.set(i * 2, 6, s_norm.y * f_norm.x);
A.set(i * 2, 7, s_norm.y * f_norm.y);
A.set(i * 2, 8, s_norm.y);
A.set(i * 2 + 1, 0, f_norm.x);
A.set(i * 2 + 1, 1, f_norm.y);
A.set(i * 2 + 1, 2, 1);
A.set(i * 2 + 1, 6, -s_norm.x * f_norm.x);
A.set(i * 2 + 1, 7, -s_norm.x * f_norm.y);
A.set(i * 2 + 1, 8, -s_norm.x);
}
}
Aggregations