Search in sources :

Example 1 with UnconstrainedLeastSquares

use of org.ddogleg.optimization.UnconstrainedLeastSquares in project BoofCV by lessthanoptimal.

the class TestTrifocalAlgebraicPoint7 method noisy.

/**
 * Give it noisy inputs and see if it produces a better solution than the non-iterative algorithm.
 */
@Test
public void noisy() {
    List<AssociatedTriple> noisyObs = new ArrayList<>();
    // create a noisy set of observations
    double noiseLevel = 0.25;
    for (AssociatedTriple p : observations) {
        AssociatedTriple n = p.copy();
        n.p1.x += rand.nextGaussian() * noiseLevel;
        n.p1.y += rand.nextGaussian() * noiseLevel;
        n.p2.x += rand.nextGaussian() * noiseLevel;
        n.p2.y += rand.nextGaussian() * noiseLevel;
        n.p3.x += rand.nextGaussian() * noiseLevel;
        n.p3.y += rand.nextGaussian() * noiseLevel;
        noisyObs.add(n);
    }
    UnconstrainedLeastSquares optimizer = FactoryOptimization.leastSquareLevenberg(1e-3);
    TrifocalAlgebraicPoint7 alg = new TrifocalAlgebraicPoint7(optimizer, 300, 1e-20, 1e-20);
    assertTrue(alg.process(noisyObs, found));
    found.normalizeScale();
    // only the induced error is tested since the constraint error has unknown units and is quite large
    checkInducedErrors(found, noisyObs, 2);
}
Also used : AssociatedTriple(boofcv.struct.geo.AssociatedTriple) ArrayList(java.util.ArrayList) UnconstrainedLeastSquares(org.ddogleg.optimization.UnconstrainedLeastSquares) Test(org.junit.Test)

Example 2 with UnconstrainedLeastSquares

use of org.ddogleg.optimization.UnconstrainedLeastSquares in project BoofCV by lessthanoptimal.

the class TestTrifocalAlgebraicPoint7 method noisy.

private void noisy(boolean planar) {
    createSceneObservations(planar);
    List<AssociatedTriple> noisyObs = new ArrayList<>();
    // create a noisy set of observations
    double noiseLevel = 0.5;
    for (AssociatedTriple p : observationsPixels) {
        AssociatedTriple n = p.copy();
        n.p1.x += rand.nextGaussian() * noiseLevel;
        n.p1.y += rand.nextGaussian() * noiseLevel;
        n.p2.x += rand.nextGaussian() * noiseLevel;
        n.p2.y += rand.nextGaussian() * noiseLevel;
        n.p3.x += rand.nextGaussian() * noiseLevel;
        n.p3.y += rand.nextGaussian() * noiseLevel;
        noisyObs.add(n);
    }
    TrifocalLinearPoint7 linear = new TrifocalLinearPoint7();
    linear.process(noisyObs, found);
    double errorLinear = computeTransferError(found, noisyObs);
    UnconstrainedLeastSquares optimizer = FactoryOptimization.levenbergMarquardt(null, true);
    TrifocalAlgebraicPoint7 alg = new TrifocalAlgebraicPoint7(optimizer, 300, 1e-20, 1e-20);
    assertTrue(alg.process(noisyObs, found));
    // only the induced error is tested since the constraint error has unknown units and is quite large
    double errorsAlg = computeTransferError(found, noisyObs);
    // it appears that the linear estimate is very accurate. This is a really a test to see if it made
    // the solution significantly worse
    assertTrue(errorsAlg <= errorLinear * 1.2);
}
Also used : AssociatedTriple(boofcv.struct.geo.AssociatedTriple) ArrayList(java.util.ArrayList) UnconstrainedLeastSquares(org.ddogleg.optimization.UnconstrainedLeastSquares)

Example 3 with UnconstrainedLeastSquares

use of org.ddogleg.optimization.UnconstrainedLeastSquares in project BoofCV by lessthanoptimal.

the class FactoryMultiView method estimateTrifocal_1.

/**
 * Creates a trifocal tensor estimation algorithm.
 *
 * @param type Which algorithm.
 * @param iterations If the algorithm is iterative, then this is the number of iterations.  Try 200
 * @return Trifocal tensor estimator
 */
public static Estimate1ofTrifocalTensor estimateTrifocal_1(EnumTrifocal type, int iterations) {
    switch(type) {
        case LINEAR_7:
            return new WrapTrifocalLinearPoint7();
        case ALGEBRAIC_7:
            UnconstrainedLeastSquares optimizer = FactoryOptimization.leastSquaresLM(1e-3, false);
            TrifocalAlgebraicPoint7 alg = new TrifocalAlgebraicPoint7(optimizer, iterations, 1e-12, 1e-12);
            return new WrapTrifocalAlgebraicPoint7(alg);
    }
    throw new IllegalArgumentException("Unknown type " + type);
}
Also used : WrapTrifocalAlgebraicPoint7(boofcv.abst.geo.trifocal.WrapTrifocalAlgebraicPoint7) TrifocalAlgebraicPoint7(boofcv.alg.geo.trifocal.TrifocalAlgebraicPoint7) WrapTrifocalAlgebraicPoint7(boofcv.abst.geo.trifocal.WrapTrifocalAlgebraicPoint7) UnconstrainedLeastSquares(org.ddogleg.optimization.UnconstrainedLeastSquares) WrapTrifocalLinearPoint7(boofcv.abst.geo.trifocal.WrapTrifocalLinearPoint7)

Example 4 with UnconstrainedLeastSquares

use of org.ddogleg.optimization.UnconstrainedLeastSquares in project BoofCV by lessthanoptimal.

the class TestTrifocalAlgebraicPoint7 method perfect.

/**
 * Give it perfect inputs and make sure it doesn't screw things up
 */
@Test
public void perfect() {
    UnconstrainedLeastSquares optimizer = FactoryOptimization.leastSquareLevenberg(1e-3);
    TrifocalAlgebraicPoint7 alg = new TrifocalAlgebraicPoint7(optimizer, 300, 1e-20, 1e-20);
    assertTrue(alg.process(observations, found));
    checkTrifocalWithConstraint(found, 1e-8);
    checkInducedErrors(found, observations, 1e-8);
}
Also used : UnconstrainedLeastSquares(org.ddogleg.optimization.UnconstrainedLeastSquares) Test(org.junit.Test)

Example 5 with UnconstrainedLeastSquares

use of org.ddogleg.optimization.UnconstrainedLeastSquares in project BoofCV by lessthanoptimal.

the class TestTrifocalAlgebraicPoint7 method perfect.

private void perfect(boolean planar) {
    createSceneObservations(planar);
    UnconstrainedLeastSquares optimizer = FactoryOptimization.levenbergMarquardt(null, false);
    TrifocalAlgebraicPoint7 alg = new TrifocalAlgebraicPoint7(optimizer, 300, 1e-20, 1e-20);
    assertTrue(alg.process(observations, found));
    checkTrifocalWithConstraint(found, 5e-7);
    assertEquals(0, computeTransferError(found, observations), UtilEjml.TEST_F64);
}
Also used : UnconstrainedLeastSquares(org.ddogleg.optimization.UnconstrainedLeastSquares)

Aggregations

UnconstrainedLeastSquares (org.ddogleg.optimization.UnconstrainedLeastSquares)5 AssociatedTriple (boofcv.struct.geo.AssociatedTriple)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 WrapTrifocalAlgebraicPoint7 (boofcv.abst.geo.trifocal.WrapTrifocalAlgebraicPoint7)1 WrapTrifocalLinearPoint7 (boofcv.abst.geo.trifocal.WrapTrifocalLinearPoint7)1 TrifocalAlgebraicPoint7 (boofcv.alg.geo.trifocal.TrifocalAlgebraicPoint7)1