Search in sources :

Example 1 with TrifocalTensor

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

the class TestMultiViewOps method createTrifocal_CameraMatrix.

/**
 * Check the trifocal tensor using its definition
 */
@Test
public void createTrifocal_CameraMatrix() {
    SimpleMatrix P1 = SimpleMatrix.wrap(PerspectiveOps.createCameraMatrix(worldToCam2.getR(), worldToCam2.getT(), null, null));
    SimpleMatrix P2 = SimpleMatrix.wrap(PerspectiveOps.createCameraMatrix(worldToCam3.getR(), worldToCam3.getT(), null, null));
    TrifocalTensor found = MultiViewOps.createTrifocal(worldToCam2, worldToCam3, null);
    for (int i = 0; i < 3; i++) {
        SimpleMatrix ai = P1.extractVector(false, i);
        SimpleMatrix b4 = P2.extractVector(false, 3);
        SimpleMatrix a4 = P1.extractVector(false, 3);
        SimpleMatrix bi = P2.extractVector(false, i);
        SimpleMatrix expected = ai.mult(b4.transpose()).minus(a4.mult(bi.transpose()));
        assertTrue(MatrixFeatures_DDRM.isIdentical(expected.getDDRM(), found.getT(i), 1e-8));
    }
}
Also used : SimpleMatrix(org.ejml.simple.SimpleMatrix) TrifocalTensor(boofcv.struct.geo.TrifocalTensor) Test(org.junit.Test)

Example 2 with TrifocalTensor

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

the class TestMultiViewOps method extractCameraMatrices.

@Test
public void extractCameraMatrices() {
    DMatrixRMaj P2 = new DMatrixRMaj(3, 4);
    DMatrixRMaj P3 = new DMatrixRMaj(3, 4);
    TrifocalTensor input = tensor.copy();
    MultiViewOps.extractCameraMatrices(input, P2, P3);
    // make sure the input was not modified
    for (int i = 0; i < 3; i++) assertTrue(MatrixFeatures_DDRM.isIdentical(tensor.getT(i), input.getT(i), 1e-8));
    // Using found camera matrices render the point's location
    Point3D_F64 X = new Point3D_F64(0.1, 0.05, 2);
    Point2D_F64 x1 = new Point2D_F64(X.x / X.z, X.y / X.z);
    Point2D_F64 x2 = PerspectiveOps.renderPixel(P2, X);
    Point2D_F64 x3 = PerspectiveOps.renderPixel(P3, X);
    // validate correctness by testing a constraint on the points
    DMatrixRMaj A = new DMatrixRMaj(3, 3);
    MultiViewOps.constraint(tensor, x1, x2, x3, A);
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            assertEquals(0, A.get(i, j), 1e-7);
        }
    }
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) TrifocalTensor(boofcv.struct.geo.TrifocalTensor) Point2D_F64(georegression.struct.point.Point2D_F64) DMatrixRMaj(org.ejml.data.DMatrixRMaj) Test(org.junit.Test)

Example 3 with TrifocalTensor

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

the class TestEnforceTrifocalGeometry method perfectInput.

/**
 * Give it a set of perfect inputs and see if it computes a valid trifocal tensor
 */
@Test
public void perfectInput() {
    // create linear constraint matrix
    TrifocalLinearPoint7 constructA = new TrifocalLinearPoint7();
    // Make things easier by working in pixel coordinates
    constructA.N1 = new NormalizationPoint2D(0, 1, 0, 1);
    constructA.N2 = new NormalizationPoint2D(0, 1, 0, 1);
    constructA.N3 = new NormalizationPoint2D(0, 1, 0, 1);
    constructA.createLinearSystem(observations);
    DMatrixRMaj A = constructA.A;
    // extract epipoles
    Point3D_F64 e2 = new Point3D_F64();
    Point3D_F64 e3 = new Point3D_F64();
    MultiViewOps.extractEpipoles(tensor, e2, e3);
    EnforceTrifocalGeometry alg = new EnforceTrifocalGeometry();
    alg.process(e2, e3, A);
    // Check if the found solution is valid by applying the trifocal constraint for 3 points
    TrifocalTensor found = new TrifocalTensor();
    alg.extractSolution(found);
    checkTrifocalWithConstraint(found, 1e-6);
    // make sure the errors are zero too
    DMatrixRMaj errors = new DMatrixRMaj(observations.size(), 1);
    alg.computeErrorVector(A, errors);
    for (int i = 0; i < errors.numRows; i++) assertEquals(0, errors.get(i), 1e-8);
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) TrifocalTensor(boofcv.struct.geo.TrifocalTensor) NormalizationPoint2D(boofcv.alg.geo.NormalizationPoint2D) DMatrixRMaj(org.ejml.data.DMatrixRMaj) Test(org.junit.Test)

Example 4 with TrifocalTensor

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

the class TestEnforceTrifocalGeometry method checkMatrixE.

/**
 * Construct a tensor from two arbitrary camera matrices.  Then provide the same inputs
 * to the algorithm and see if the matrix is constructed correctly.
 */
@Test
public void checkMatrixE() {
    DMatrixRMaj P2 = new DMatrixRMaj(3, 4, true, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
    DMatrixRMaj P3 = new DMatrixRMaj(3, 4, true, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120);
    Point3D_F64 e2 = new Point3D_F64(P2.get(0, 3), P2.get(1, 3), P2.get(2, 3));
    Point3D_F64 e3 = new Point3D_F64(P3.get(0, 3), P3.get(1, 3), P3.get(2, 3));
    TrifocalTensor tensor = MultiViewOps.createTrifocal(P2, P3, null);
    EnforceTrifocalGeometry alg = new EnforceTrifocalGeometry();
    alg.constructE(e2, e3);
    DMatrixRMaj X = new DMatrixRMaj(18, 1);
    for (int i = 0; i < 9; i++) {
        X.data[i] = P2.get(i / 3, i % 3);
        X.data[i + 9] = P3.get(i / 3, i % 3);
    }
    DMatrixRMaj vectorT = new DMatrixRMaj(27, 1);
    CommonOps_DDRM.mult(alg.E, X, vectorT);
    TrifocalTensor foundT = new TrifocalTensor();
    foundT.convertFrom(vectorT);
    // the two tensors should be identical
    for (int i = 0; i < 3; i++) {
        assertTrue(MatrixFeatures_DDRM.isIdentical(tensor.getT(i), foundT.getT(i), 1e-8));
    }
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) TrifocalTensor(boofcv.struct.geo.TrifocalTensor) DMatrixRMaj(org.ejml.data.DMatrixRMaj) Test(org.junit.Test)

Example 5 with TrifocalTensor

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

the class TestTrifocalExtractEpipoles method basicCheck.

/**
 * Randomly general several scenarios and see if it produces the correct solution
 */
@Test
public void basicCheck() {
    TrifocalExtractEpipoles alg = new TrifocalExtractEpipoles();
    for (int i = 0; i < 5; i++) {
        createRandomScenario();
        Point3D_F64 found2 = new Point3D_F64();
        Point3D_F64 found3 = new Point3D_F64();
        TrifocalTensor input = tensor.copy();
        alg.process(input, found2, found3);
        // make sure the input was not modified
        for (int j = 0; j < 3; j++) assertTrue(MatrixFeatures_DDRM.isIdentical(tensor.getT(j), input.getT(j), 1e-8));
        Point3D_F64 space = new Point3D_F64();
        // check to see if it is the left-null space of their respective Fundamental matrices
        GeometryMath_F64.multTran(F2, found2, space);
        assertEquals(0, space.norm(), 1e-8);
        GeometryMath_F64.multTran(F3, found3, space);
        assertEquals(0, space.norm(), 1e-8);
    }
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) TrifocalTensor(boofcv.struct.geo.TrifocalTensor) Test(org.junit.Test)

Aggregations

TrifocalTensor (boofcv.struct.geo.TrifocalTensor)10 Test (org.junit.Test)8 Point3D_F64 (georegression.struct.point.Point3D_F64)6 DMatrixRMaj (org.ejml.data.DMatrixRMaj)6 Point2D_F64 (georegression.struct.point.Point2D_F64)2 SimpleMatrix (org.ejml.simple.SimpleMatrix)2 NormalizationPoint2D (boofcv.alg.geo.NormalizationPoint2D)1 Vector3D_F64 (georegression.struct.point.Vector3D_F64)1 Se3_F64 (georegression.struct.se.Se3_F64)1