Search in sources :

Example 6 with Equation

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

the class TestDecomposeProjectiveToMetric method projectiveToMetric.

@Test
void projectiveToMetric() {
    var alg = new DecomposeProjectiveToMetric();
    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();
        assertTrue(alg.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 7 with Equation

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

the class TestDecomposeProjectiveToMetric method projectiveToMetricKnownK.

@Test
void projectiveToMetricKnownK() {
    var alg = new DecomposeProjectiveToMetric();
    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(alg.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 8 with Equation

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

the class TestPerspectiveOps method multTranA_triple_dense.

@Test
void multTranA_triple_dense() {
    DMatrixRMaj A = RandomMatrices_DDRM.rectangle(3, 3, rand);
    DMatrixRMaj B = RandomMatrices_DDRM.rectangle(3, 3, rand);
    DMatrixRMaj C = RandomMatrices_DDRM.rectangle(3, 3, rand);
    DMatrixRMaj D = RandomMatrices_DDRM.rectangle(3, 3, rand);
    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_DDRM.isEquals(expected, D, UtilEjml.TEST_F64));
}
Also used : DMatrixRMaj(org.ejml.data.DMatrixRMaj) Equation(org.ejml.equation.Equation) Test(org.junit.jupiter.api.Test)

Example 9 with Equation

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

the class TestPerspectiveOps method multTranC_triple_fixed.

@Test
void multTranC_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.multTranC(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)

Example 10 with Equation

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

the class TestHomographyTotalLeastSquares method constructA678.

@Test
void constructA678() {
    int N = 10;
    SimpleMatrix P = SimpleMatrix.random_DDRM(N, 2, -1, 1, rand);
    SimpleMatrix X = SimpleMatrix.random_DDRM(N, 2, -1, 1, rand);
    Equation eq = new Equation();
    eq.alias(P.copy(), "P", X.copy(), "X", N, "N");
    eq.process("X=-X");
    eq.process("Xd = diag(X(:,0))");
    eq.process("Yd = diag(X(:,1))");
    eq.process("One=ones(N,1)");
    eq.process("Pp=inv(P'*P)*P'");
    eq.process("XP=(X'*P)/N");
    eq.process("top    = [Xd*P-One*XP(0,:)-P*Pp*Xd*P , X(:,0)-P*Pp*X(:,0)]");
    eq.process("bottom = [Yd*P-One*XP(1,:)-P*Pp*Yd*P , X(:,1)-P*Pp*X(:,1)]");
    eq.process("A=[top;bottom]");
    HomographyTotalLeastSquares alg = new HomographyTotalLeastSquares();
    alg.X1.setTo(P.getDDRM());
    alg.X2.setTo(X.getDDRM());
    alg.constructA678();
    assertTrue(MatrixFeatures_DDRM.isIdentical(eq.lookupDDRM("A"), alg.A, UtilEjml.TEST_F64));
}
Also used : SimpleMatrix(org.ejml.simple.SimpleMatrix) Equation(org.ejml.equation.Equation) 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