Search in sources :

Example 6 with DMatrix4x4

use of org.ejml.data.DMatrix4x4 in project BoofCV by lessthanoptimal.

the class TestDecomposeAbsoluteDualQuadratic method computeRectifyingHomography.

/**
 * Create a dual quadratic from its definition and see if its correctly decomposed
 */
@Test
void computeRectifyingHomography() {
    Equation eq = new Equation(K, "K");
    DMatrixRMaj Q = eq.process("I=diag([1,1,1,0])").process("p=[2.1;0.4;-0.3]").process("H=[K [0;0;0];-p'*K 1]").process("Q=H*I*H'").process(// change scale of Q to make it more interesting
    "Q=Q*1e-3").lookupDDRM("Q");
    DMatrixRMaj H = eq.lookupDDRM("H");
    DMatrix4x4 _Q = new DMatrix4x4();
    DConvertMatrixStruct.convert(Q, _Q);
    DecomposeAbsoluteDualQuadratic alg = new DecomposeAbsoluteDualQuadratic();
    assertTrue(alg.decompose(_Q));
    DMatrixRMaj foundH = new DMatrixRMaj(4, 4);
    assertTrue(alg.computeRectifyingHomography(foundH));
    assertTrue(MatrixFeatures_DDRM.isIdentical(H, foundH, UtilEjml.TEST_F64));
    assertTrue(MatrixFeatures_D.isIdentical(K, alg.getK(), 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 7 with DMatrix4x4

use of org.ejml.data.DMatrix4x4 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)

Aggregations

DMatrix4x4 (org.ejml.data.DMatrix4x4)7 DMatrixRMaj (org.ejml.data.DMatrixRMaj)7 Equation (org.ejml.equation.Equation)7 Test (org.junit.jupiter.api.Test)7 DMatrix3 (org.ejml.data.DMatrix3)1 DMatrix3x3 (org.ejml.data.DMatrix3x3)1