Search in sources :

Example 26 with Equation

use of org.ejml.equation.Equation in project BoofCV by lessthanoptimal.

the class TestMultiViewOps method projectiveToMetric.

@Test
void projectiveToMetric() {
    DMatrixRMaj K = PerspectiveOps.pinholeToMatrix(200, 250, 0.0, 100, 110);
    DMatrixRMaj foundK = new DMatrixRMaj(3, 3);
    for (int i = 0; i < 50; i++) {
        double Tx = rand.nextGaussian();
        double Ty = rand.nextGaussian();
        double Tz = rand.nextGaussian();
        double rotX = rand.nextGaussian();
        double rotY = rand.nextGaussian();
        double rotZ = rand.nextGaussian();
        Se3_F64 m = SpecialEuclideanOps_F64.eulerXyz(Tx, Ty, Tz, rotX, rotY, rotZ, null);
        DMatrixRMaj P = PerspectiveOps.createCameraMatrix(m.R, m.T, K, null);
        // mess up the scale of P
        CommonOps_DDRM.scale(0.9, P, P);
        Equation eq = new Equation(P, "P", K, "K");
        eq.process("p=[-0.9,0.1,0.7]'").process("H=[K zeros(3,1);-p'*K 1]").process("P=P*H").process("H_inv=inv(H)");
        DMatrixRMaj H_inv = eq.lookupDDRM("H_inv");
        Se3_F64 found = new Se3_F64();
        MultiViewOps.projectiveToMetric(P, H_inv, found, foundK);
        assertTrue(MatrixFeatures_DDRM.isEquals(K, foundK, UtilEjml.TEST_F64));
        assertEquals(0, m.T.distance(found.T), UtilEjml.TEST_F64);
    }
}
Also used : DMatrixRMaj(org.ejml.data.DMatrixRMaj) Equation(org.ejml.equation.Equation) Se3_F64(georegression.struct.se.Se3_F64) Test(org.junit.jupiter.api.Test)

Example 27 with Equation

use of org.ejml.equation.Equation in project BoofCV by lessthanoptimal.

the class TestMultiViewOps method projectiveToMetricKnownK.

@Test
void projectiveToMetricKnownK() {
    DMatrixRMaj K = PerspectiveOps.pinholeToMatrix(200, 250, 0.0, 100, 110);
    for (int i = 0; i < 50; i++) {
        double Tx = rand.nextGaussian();
        double Ty = rand.nextGaussian();
        double Tz = rand.nextGaussian();
        double rotX = rand.nextGaussian();
        double rotY = rand.nextGaussian();
        double rotZ = rand.nextGaussian();
        Se3_F64 m = SpecialEuclideanOps_F64.eulerXyz(Tx, Ty, Tz, rotX, rotY, rotZ, null);
        DMatrixRMaj P = PerspectiveOps.createCameraMatrix(m.R, m.T, K, null);
        // mess up the scale of P
        CommonOps_DDRM.scale(0.9, P, P);
        Equation eq = new Equation(P, "P", K, "K");
        eq.process("p=[-0.9,0.1,0.7]'").process("H=[K zeros(3,1);-p'*K 1]").process("P=P*H").process("H_inv=inv(H)");
        DMatrixRMaj H_inv = eq.lookupDDRM("H_inv");
        Se3_F64 found = new Se3_F64();
        assertTrue(MultiViewOps.projectiveToMetricKnownK(P, H_inv, K, found));
        assertEquals(0, m.T.distance(found.T), UtilEjml.TEST_F64);
    }
}
Also used : DMatrixRMaj(org.ejml.data.DMatrixRMaj) Equation(org.ejml.equation.Equation) Se3_F64(georegression.struct.se.Se3_F64) Test(org.junit.jupiter.api.Test)

Example 28 with Equation

use of org.ejml.equation.Equation in project BoofCV by lessthanoptimal.

the class TestMultiViewOps method enforceAbsoluteQuadraticConstraints_negative.

/**
 * Give it a valid Q but have the sign be inverted
 */
@Test
void enforceAbsoluteQuadraticConstraints_negative() {
    Equation eq = new Equation();
    eq.process("K=[300 1 50;0 310 60; 0 0 1]");
    eq.process("p=rand(3,1)");
    eq.process("u=-p'*K");
    eq.process("H=[K [0;0;0]; u 1]");
    eq.process("Q=H*diag([1 1 1 0])*H'");
    DMatrixRMaj Q = eq.lookupDDRM("Q");
    DMatrix4x4 Q_neg = new DMatrix4x4();
    DConvertMatrixStruct.convert(Q, Q_neg);
    // negative and non-standard scale
    CommonOps_DDF4.scale(-0.045, Q_neg);
    MultiViewOps.enforceAbsoluteQuadraticConstraints(Q_neg, false, false);
    // change scale so that the test tolerance is reasonable
    CommonOps_DDRM.scale(1.0 / Math.abs(Q.get(3, 3)), Q);
    CommonOps_DDF4.scale(1.0 / Math.abs(Q_neg.a44), Q_neg);
    assertTrue(MatrixFeatures_D.isIdentical(Q, Q_neg, UtilEjml.TEST_F64));
}
Also used : DMatrixRMaj(org.ejml.data.DMatrixRMaj) DMatrix4x4(org.ejml.data.DMatrix4x4) Equation(org.ejml.equation.Equation) Test(org.junit.jupiter.api.Test)

Example 29 with Equation

use of org.ejml.equation.Equation in project BoofCV by lessthanoptimal.

the class TestMultiViewOps method canonicalRectifyingHomographyFromKPinf.

@Test
void canonicalRectifyingHomographyFromKPinf() {
    Equation eq = new Equation();
    eq.process("K=[300 1 50;0 310 60; 0 0 1]");
    eq.process("p=rand(3,1)");
    eq.process("u=-p'*K");
    eq.process("H=[K [0;0;0]; u 1]");
    DMatrixRMaj K = eq.lookupDDRM("K");
    DMatrixRMaj p = eq.lookupDDRM("p");
    Point3D_F64 _p = new Point3D_F64(p.get(0), p.get(1), p.get(2));
    // wrong size intentionally
    DMatrixRMaj found = new DMatrixRMaj(1, 1);
    MultiViewOps.canonicalRectifyingHomographyFromKPinf(K, _p, found);
    assertTrue(MatrixFeatures_DDRM.isEquals(eq.lookupDDRM("H"), found, UtilEjml.TEST_F64));
}
Also used : UtilPoint3D_F64(georegression.geometry.UtilPoint3D_F64) Point3D_F64(georegression.struct.point.Point3D_F64) DMatrixRMaj(org.ejml.data.DMatrixRMaj) Equation(org.ejml.equation.Equation) Test(org.junit.jupiter.api.Test)

Example 30 with Equation

use of org.ejml.equation.Equation in project BoofCV by lessthanoptimal.

the class TestPerspectiveOps method multTranA_triple_fixed.

@Test
void multTranA_triple_fixed() {
    DMatrix3x3 A = random3x3();
    DMatrix3x3 B = random3x3();
    DMatrix3x3 C = random3x3();
    DMatrix3x3 D = random3x3();
    Equation eq = new Equation(A, "A", B, "B", C, "C");
    eq.process("D=A'*B*C");
    DMatrixRMaj expected = eq.lookupDDRM("D");
    PerspectiveOps.multTranA(A, B, C, D);
    assertTrue(MatrixFeatures_D.isEquals(expected, D));
}
Also used : DMatrixRMaj(org.ejml.data.DMatrixRMaj) Equation(org.ejml.equation.Equation) DMatrix3x3(org.ejml.data.DMatrix3x3) Test(org.junit.jupiter.api.Test)

Aggregations

Equation (org.ejml.equation.Equation)31 DMatrixRMaj (org.ejml.data.DMatrixRMaj)29 Test (org.junit.jupiter.api.Test)28 DMatrix4x4 (org.ejml.data.DMatrix4x4)7 CameraPinhole (boofcv.struct.calib.CameraPinhole)5 Se3_F64 (georegression.struct.se.Se3_F64)5 Homography2D_F64 (georegression.struct.homography.Homography2D_F64)3 ArrayList (java.util.ArrayList)3 DMatrix3x3 (org.ejml.data.DMatrix3x3)3 UtilPoint3D_F64 (georegression.geometry.UtilPoint3D_F64)2 Point2D_F64 (georegression.struct.point.Point2D_F64)2 Point3D_F64 (georegression.struct.point.Point3D_F64)2 DMatrix2x2 (org.ejml.data.DMatrix2x2)2 SimpleMatrix (org.ejml.simple.SimpleMatrix)2 TrifocalTensor (boofcv.struct.geo.TrifocalTensor)1 Vector3D_F64 (georegression.struct.point.Vector3D_F64)1 DMatrix3 (org.ejml.data.DMatrix3)1