use of org.ejml.equation.Equation in project BoofCV by lessthanoptimal.
the class TestDecomposeAbsoluteDualQuadratic method decompose.
@Test
void decompose() {
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 w = eq.process("w=Q(0:2,0:2)").lookupDDRM("w");
DMatrixRMaj p = eq.process("p=-inv(w)*Q(0:2,3)").lookupDDRM("p");
DMatrix4x4 _Q = new DMatrix4x4();
DConvertMatrixStruct.convert(Q, _Q);
DecomposeAbsoluteDualQuadratic alg = new DecomposeAbsoluteDualQuadratic();
assertTrue(alg.decompose(_Q));
CommonOps_DDRM.scale(1.0 / w.get(2, 2), w);
assertTrue(MatrixFeatures_D.isIdentical(w, alg.getW(), UtilEjml.TEST_F64));
assertTrue(MatrixFeatures_D.isIdentical(p, alg.getP(), UtilEjml.TEST_F64));
}
use of org.ejml.equation.Equation 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));
}
use of org.ejml.equation.Equation in project BoofCV by lessthanoptimal.
the class TestMultiViewOps method projectiveToFundamental_Two.
@Test
void projectiveToFundamental_Two() {
DMatrixRMaj K = PerspectiveOps.pinholeToMatrix(200, 250, 0.0, 400, 405);
Se3_F64 M11 = new Se3_F64();
Se3_F64 M12 = SpecialEuclideanOps_F64.eulerXyz(-1, 0, -0.2, EulerType.XYZ, 0, -.2, 0, null);
DMatrixRMaj P1 = PerspectiveOps.createCameraMatrix(M11.R, M11.T, K, null);
DMatrixRMaj P2 = PerspectiveOps.createCameraMatrix(M12.R, M12.T, K, null);
DMatrixRMaj F21 = MultiViewOps.projectiveToFundamental(P1, P2, null);
// test by seeing if a skew symmetric matrix is produced with the formula below
Equation eq = new Equation(P1, "P1", P2, "P2", F21, "F21");
eq.process("A = P2'*F21*P1");
DMatrixRMaj A = eq.lookupDDRM("A");
for (int row = 0; row < 4; row++) {
for (int col = row + 1; col < 4; col++) {
assertEquals(A.get(row, col), -A.get(col, row), 1e-8);
}
}
}
use of org.ejml.equation.Equation in project BoofCV by lessthanoptimal.
the class TestMultiViewOps method decomposeDiac.
@Test
void decomposeDiac() {
Equation eq = new Equation();
eq.process("K=[300 1 50;0 310 60; 0 0 1]");
eq.process("w=1.5*K*K'");
DMatrixRMaj w = eq.lookupDDRM("w");
CameraPinhole intrinsic = new CameraPinhole();
MultiViewOps.decomposeDiac(w, intrinsic);
assertEquals(300, intrinsic.fx);
assertEquals(310, intrinsic.fy);
assertEquals(50, intrinsic.cx);
assertEquals(60, intrinsic.cy);
assertEquals(1, intrinsic.skew);
}
use of org.ejml.equation.Equation in project BoofCV by lessthanoptimal.
the class TestMultiViewOps method createTrifocal_CameraMatrix2.
/**
* Check the trifocal tensor using its definition
*/
@Test
void createTrifocal_CameraMatrix2() {
TrifocalTensor found = MultiViewOps.createTrifocal(P2, P3, null);
List<Point3D_F64> points = UtilPoint3D_F64.random(new Point3D_F64(0, 0, 2), -1, 1, -1, -1, -0.1, 0.1, 20, rand);
// Test it against a constraint
DMatrixRMaj C = RandomMatrices_DDRM.rectangle(3, 3, -1, 1, rand);
for (Point3D_F64 X : points) {
Point2D_F64 x1 = PerspectiveOps.renderPixel(worldToCam1, X, null);
Point2D_F64 x2 = PerspectiveOps.renderPixel(worldToCam2, K, X, null);
Point2D_F64 x3 = PerspectiveOps.renderPixel(worldToCam3, K, X, null);
MultiViewOps.constraint(found, x1, x2, x3, C);
for (int i = 0; i < 9; i++) {
assertEquals(0, C.data[i], 10 * UtilEjml.TEST_F64);
}
}
// test it against its definition
Equation eq = new Equation(P2, "P2", P3, "P3");
for (int i = 0; i < 3; i++) {
eq.alias(i, "i");
eq.process("ai = P2(:,i)");
eq.process("b4 = P3(:,3)");
eq.process("a4 = P2(:,3)");
eq.process("bi = P3(:,i)");
eq.process("z = ai*b4' - a4*bi'");
DMatrixRMaj expected = eq.lookupDDRM("z");
assertTrue(MatrixFeatures_DDRM.isIdentical(expected, found.getT(i), UtilEjml.TEST_F64));
}
}
Aggregations