Search in sources :

Example 6 with AssociatedTriple

use of boofcv.struct.geo.AssociatedTriple in project BoofCV by lessthanoptimal.

the class TestTrifocalLinearPoint7 method fullTest.

@Test
public void fullTest() {
    TrifocalLinearPoint7 alg = new TrifocalLinearPoint7();
    assertTrue(alg.process(observations, found));
    // validate the solution by using a constraint
    for (AssociatedTriple a : observations) {
        DMatrixRMaj A = MultiViewOps.constraint(found, a.p1, a.p2, a.p3, null);
        assertEquals(0, NormOps_DDRM.normF(A), 1e-7);
    }
}
Also used : AssociatedTriple(boofcv.struct.geo.AssociatedTriple) DMatrixRMaj(org.ejml.data.DMatrixRMaj) Test(org.junit.Test)

Example 7 with AssociatedTriple

use of boofcv.struct.geo.AssociatedTriple in project BoofCV by lessthanoptimal.

the class TrifocalLinearPoint7 method createLinearSystem.

/**
 * Constructs the linear matrix that describes from the 3-point constraint with linear
 * dependent rows removed
 */
protected void createLinearSystem(List<AssociatedTriple> observations) {
    int N = observations.size();
    A.reshape(4 * N, 27);
    A.zero();
    int index1 = 0;
    for (int i = 0; i < N; i++) {
        AssociatedTriple t = observations.get(i);
        N1.apply(t.p1, p1_norm);
        N2.apply(t.p2, p2_norm);
        N3.apply(t.p3, p3_norm);
        int index2 = index1 + 9;
        int index3 = index1 + 18;
        // i = 1, j = 1
        A.data[index1 + 8] = p1_norm.x * p2_norm.x * p3_norm.x;
        A.data[index1 + 2] = -p1_norm.x * p3_norm.x;
        A.data[index1 + 6] = -p1_norm.x * p2_norm.x;
        A.data[index1] = p1_norm.x;
        A.data[index2 + 8] = p1_norm.y * p2_norm.x * p3_norm.x;
        A.data[index2 + 2] = -p1_norm.y * p3_norm.x;
        A.data[index2 + 6] = -p1_norm.y * p2_norm.x;
        A.data[index2] = p1_norm.y;
        A.data[index3 + 8] = p2_norm.x * p3_norm.x;
        A.data[index3 + 2] = -p3_norm.x;
        A.data[index3 + 6] = -p2_norm.x;
        A.data[index3] = 1;
        // i = 1, j = 2;
        index1 += 27;
        index2 = index1 + 9;
        index3 = index1 + 18;
        A.data[index1 + 8] = p1_norm.x * p2_norm.x * p3_norm.y;
        A.data[index1 + 2] = -p1_norm.x * p3_norm.y;
        A.data[index1 + 7] = -p1_norm.x * p2_norm.x;
        A.data[index1 + 1] = p1_norm.x;
        A.data[index2 + 8] = p1_norm.y * p2_norm.x * p3_norm.y;
        A.data[index2 + 2] = -p1_norm.y * p3_norm.y;
        A.data[index2 + 7] = -p1_norm.y * p2_norm.x;
        A.data[index2 + 1] = p1_norm.y;
        A.data[index3 + 8] = p2_norm.x * p3_norm.y;
        A.data[index3 + 2] = -p3_norm.y;
        A.data[index3 + 7] = -p2_norm.x;
        A.data[index3 + 1] = 1;
        // i = 2, j = 2;
        index1 += 27;
        index2 = index1 + 9;
        index3 = index1 + 18;
        A.data[index1 + 8] = p1_norm.x * p2_norm.y * p3_norm.y;
        A.data[index1 + 5] = -p1_norm.x * p3_norm.y;
        A.data[index1 + 7] = -p1_norm.x * p2_norm.y;
        A.data[index1 + 4] = p1_norm.x;
        A.data[index2 + 8] = p1_norm.y * p2_norm.y * p3_norm.y;
        A.data[index2 + 5] = -p1_norm.y * p3_norm.y;
        A.data[index2 + 7] = -p1_norm.y * p2_norm.y;
        A.data[index2 + 4] = p1_norm.y;
        A.data[index3 + 8] = p2_norm.y * p3_norm.y;
        A.data[index3 + 5] = -p3_norm.y;
        A.data[index3 + 7] = -p2_norm.y;
        A.data[index3 + 4] = 1;
        // i = 2, j = 1;
        index1 += 27;
        index2 = index1 + 9;
        index3 = index1 + 18;
        A.data[index1 + 8] = p1_norm.x * p2_norm.y * p3_norm.x;
        A.data[index1 + 5] = -p1_norm.x * p3_norm.x;
        A.data[index1 + 6] = -p1_norm.x * p2_norm.y;
        A.data[index1 + 3] = p1_norm.x;
        A.data[index2 + 8] = p1_norm.y * p2_norm.y * p3_norm.x;
        A.data[index2 + 5] = -p1_norm.y * p3_norm.x;
        A.data[index2 + 6] = -p1_norm.y * p2_norm.y;
        A.data[index2 + 3] = p1_norm.y;
        A.data[index3 + 8] = p2_norm.y * p3_norm.x;
        A.data[index3 + 5] = -p3_norm.x;
        A.data[index3 + 6] = -p2_norm.y;
        A.data[index3 + 3] = 1;
        index1 += 27;
    }
}
Also used : AssociatedTriple(boofcv.struct.geo.AssociatedTriple)

Example 8 with AssociatedTriple

use of boofcv.struct.geo.AssociatedTriple in project BoofCV by lessthanoptimal.

the class LowLevelMultiViewOps method computeNormalization.

/**
 * <p>
 * Computes three normalization matrices for each set of point correspondences in the list of
 * {@link boofcv.struct.geo.AssociatedTriple}.  Same as {@link #computeNormalization(java.util.List, NormalizationPoint2D)},
 * but for three views.
 * </p>
 *
 * @param points Input: List of observed points that are to be normalized. Not modified.
 * @param N1 Output: 3x3 normalization matrix for first set of points. Modified.
 * @param N2 Output: 3x3 normalization matrix for second set of points. Modified.
 * @param N3 Output: 3x3 normalization matrix for third set of points. Modified.
 */
public static void computeNormalization(List<AssociatedTriple> points, NormalizationPoint2D N1, NormalizationPoint2D N2, NormalizationPoint2D N3) {
    double meanX1 = 0;
    double meanY1 = 0;
    double meanX2 = 0;
    double meanY2 = 0;
    double meanX3 = 0;
    double meanY3 = 0;
    for (AssociatedTriple p : points) {
        meanX1 += p.p1.x;
        meanY1 += p.p1.y;
        meanX2 += p.p2.x;
        meanY2 += p.p2.y;
        meanX3 += p.p3.x;
        meanY3 += p.p3.y;
    }
    meanX1 /= points.size();
    meanY1 /= points.size();
    meanX2 /= points.size();
    meanY2 /= points.size();
    meanX3 /= points.size();
    meanY3 /= points.size();
    double stdX1 = 0;
    double stdY1 = 0;
    double stdX2 = 0;
    double stdY2 = 0;
    double stdX3 = 0;
    double stdY3 = 0;
    for (AssociatedTriple p : points) {
        double dx = p.p1.x - meanX1;
        double dy = p.p1.y - meanY1;
        stdX1 += dx * dx;
        stdY1 += dy * dy;
        dx = p.p2.x - meanX2;
        dy = p.p2.y - meanY2;
        stdX2 += dx * dx;
        stdY2 += dy * dy;
        dx = p.p3.x - meanX3;
        dy = p.p3.y - meanY3;
        stdX3 += dx * dx;
        stdY3 += dy * dy;
    }
    N1.meanX = meanX1;
    N1.meanY = meanY1;
    N2.meanX = meanX2;
    N2.meanY = meanY2;
    N3.meanX = meanX3;
    N3.meanY = meanY3;
    N1.stdX = Math.sqrt(stdX1 / points.size());
    N1.stdY = Math.sqrt(stdY1 / points.size());
    N2.stdX = Math.sqrt(stdX2 / points.size());
    N2.stdY = Math.sqrt(stdY2 / points.size());
    N3.stdX = Math.sqrt(stdX3 / points.size());
    N3.stdY = Math.sqrt(stdY3 / points.size());
}
Also used : AssociatedTriple(boofcv.struct.geo.AssociatedTriple)

Example 9 with AssociatedTriple

use of boofcv.struct.geo.AssociatedTriple in project BoofCV by lessthanoptimal.

the class TestLowLevelMultiViewOps method computeNormalization_three.

/**
 * Compare to single list function
 */
@Test
public void computeNormalization_three() {
    List<AssociatedTriple> list = new ArrayList<>();
    for (int i = 0; i < 12; i++) {
        AssociatedTriple p = new AssociatedTriple();
        p.p1.set(rand.nextDouble() * 5, rand.nextDouble() * 5);
        p.p2.set(rand.nextDouble() * 5, rand.nextDouble() * 5);
        p.p3.set(rand.nextDouble() * 5, rand.nextDouble() * 5);
        list.add(p);
    }
    List<Point2D_F64> list1 = new ArrayList<>();
    List<Point2D_F64> list2 = new ArrayList<>();
    List<Point2D_F64> list3 = new ArrayList<>();
    PerspectiveOps.splitAssociated(list, list1, list2, list3);
    NormalizationPoint2D expected1 = new NormalizationPoint2D();
    NormalizationPoint2D expected2 = new NormalizationPoint2D();
    NormalizationPoint2D expected3 = new NormalizationPoint2D();
    LowLevelMultiViewOps.computeNormalization(list1, expected1);
    LowLevelMultiViewOps.computeNormalization(list2, expected2);
    LowLevelMultiViewOps.computeNormalization(list3, expected3);
    NormalizationPoint2D found1 = new NormalizationPoint2D();
    NormalizationPoint2D found2 = new NormalizationPoint2D();
    NormalizationPoint2D found3 = new NormalizationPoint2D();
    LowLevelMultiViewOps.computeNormalization(list, found1, found2, found3);
    assertTrue(expected1.isEquals(found1, 1e-8));
    assertTrue(expected2.isEquals(found2, 1e-8));
    assertTrue(expected3.isEquals(found3, 1e-8));
}
Also used : AssociatedTriple(boofcv.struct.geo.AssociatedTriple) Point2D_F64(georegression.struct.point.Point2D_F64) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 10 with AssociatedTriple

use of boofcv.struct.geo.AssociatedTriple in project BoofCV by lessthanoptimal.

the class TestPerspectiveOps method splitAssociated_triple.

@Test
public void splitAssociated_triple() {
    List<AssociatedTriple> list = new ArrayList<>();
    for (int i = 0; i < 12; i++) {
        AssociatedTriple p = new AssociatedTriple();
        p.p1.set(rand.nextDouble() * 5, rand.nextDouble() * 5);
        p.p2.set(rand.nextDouble() * 5, rand.nextDouble() * 5);
        p.p3.set(rand.nextDouble() * 5, rand.nextDouble() * 5);
        list.add(p);
    }
    List<Point2D_F64> list1 = new ArrayList<>();
    List<Point2D_F64> list2 = new ArrayList<>();
    List<Point2D_F64> list3 = new ArrayList<>();
    PerspectiveOps.splitAssociated(list, list1, list2, list3);
    assertEquals(list.size(), list1.size());
    assertEquals(list.size(), list2.size());
    assertEquals(list.size(), list3.size());
    for (int i = 0; i < list.size(); i++) {
        assertTrue(list.get(i).p1 == list1.get(i));
        assertTrue(list.get(i).p2 == list2.get(i));
        assertTrue(list.get(i).p3 == list3.get(i));
    }
}
Also used : AssociatedTriple(boofcv.struct.geo.AssociatedTriple) Point2D_F64(georegression.struct.point.Point2D_F64) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

AssociatedTriple (boofcv.struct.geo.AssociatedTriple)10 Test (org.junit.Test)4 Point2D_F64 (georegression.struct.point.Point2D_F64)3 ArrayList (java.util.ArrayList)3 DMatrixRMaj (org.ejml.data.DMatrixRMaj)3 Point3D_F64 (georegression.struct.point.Point3D_F64)1 Vector3D_F64 (georegression.struct.point.Vector3D_F64)1 Se3_F64 (georegression.struct.se.Se3_F64)1 UnconstrainedLeastSquares (org.ddogleg.optimization.UnconstrainedLeastSquares)1