use of org.ejml.simple.SimpleMatrix in project BoofCV by lessthanoptimal.
the class RectifyFundamental method process.
/**
* Compute rectification transforms for the stereo pair given a fundamental matrix and its observations.
*
* @param F Fundamental matrix
* @param observations Observations used to compute F
* @param width Width of first image.
* @param height Height of first image.
*/
public void process(DMatrixRMaj F, List<AssociatedPair> observations, int width, int height) {
int centerX = width / 2;
int centerY = height / 2;
MultiViewOps.extractEpipoles(F, epipole1, epipole2);
checkEpipoleInside(width, height);
// compute the transform H which will send epipole2 to infinity
SimpleMatrix R = rotateEpipole(epipole2, centerX, centerY);
SimpleMatrix T = translateToOrigin(centerX, centerY);
SimpleMatrix G = computeG(epipole2, centerX, centerY);
SimpleMatrix H = G.mult(R).mult(T);
// Find the two matching transforms
SimpleMatrix Hzero = computeHZero(F, epipole2, H);
SimpleMatrix Ha = computeAffineH(observations, H.getDDRM(), Hzero.getDDRM());
rect1.setTo(Ha.mult(Hzero).getDDRM());
rect2.setTo(H.getDDRM());
}
use of org.ejml.simple.SimpleMatrix in project BoofCV by lessthanoptimal.
the class ImplRectifyImageOps_F64 method adjustUncalibrated.
/**
* Internal function which applies the rectification adjustment to an uncalibrated stereo pair
*/
private static void adjustUncalibrated(DMatrixRMaj rectifyLeft, DMatrixRMaj rectifyRight, RectangleLength2D_F64 bound, double scale) {
// translation
double deltaX = -bound.x0 * scale;
double deltaY = -bound.y0 * scale;
// adjustment matrix
SimpleMatrix A = new SimpleMatrix(3, 3, true, new double[] { scale, 0, deltaX, 0, scale, deltaY, 0, 0, 1 });
SimpleMatrix rL = SimpleMatrix.wrap(rectifyLeft);
SimpleMatrix rR = SimpleMatrix.wrap(rectifyRight);
rectifyLeft.setTo(A.mult(rL).getDDRM());
rectifyRight.setTo(A.mult(rR).getDDRM());
}
use of org.ejml.simple.SimpleMatrix in project BoofCV by lessthanoptimal.
the class RectifyFundamental method rotateEpipole.
/**
* Apply a rotation such that the epipole is equal to [f,0,1]
*/
static SimpleMatrix rotateEpipole(Point3D_F64 epipole, int x0, int y0) {
// compute rotation which will set
// x * sin(theta) + y * cos(theta) = 0
double x = epipole.x / epipole.z - x0;
double y = epipole.y / epipole.z - y0;
double theta = Math.atan2(-y, x);
double c = Math.cos(theta);
double s = Math.sin(theta);
SimpleMatrix R = new SimpleMatrix(3, 3);
R.setRow(0, 0, c, -s);
R.setRow(1, 0, s, c);
R.set(2, 2, 1);
return R;
}
use of org.ejml.simple.SimpleMatrix in project BoofCV by lessthanoptimal.
the class RectifyFundamental method computeHZero.
/**
* H0 = H*M
* P=[M|m] from canonical camera
*/
private SimpleMatrix computeHZero(DMatrixRMaj F, Point3D_F64 e2, SimpleMatrix H) {
Vector3D_F64 v = new Vector3D_F64(.1, 0.5, .2);
// need to make sure M is not singular for this technique to work
SimpleMatrix P = SimpleMatrix.wrap(MultiViewOps.fundamentalToProjective(F, e2, v, 1));
SimpleMatrix M = P.extractMatrix(0, 3, 0, 3);
return H.mult(M);
}
use of org.ejml.simple.SimpleMatrix in project BoofCV by lessthanoptimal.
the class TestPerspectiveOps method createCameraMatrix.
@Test
void createCameraMatrix() {
SimpleMatrix R = SimpleMatrix.random_DDRM(3, 3, -1, 1, rand);
Vector3D_F64 T = new Vector3D_F64(2, 3, -4);
SimpleMatrix K = SimpleMatrix.wrap(RandomMatrices_DDRM.triangularUpper(3, 0, -1, 1, rand));
SimpleMatrix T_ = new SimpleMatrix(3, 1, true, new double[] { T.x, T.y, T.z });
// test calibrated camera
DMatrixRMaj found = PerspectiveOps.createCameraMatrix(R.getDDRM(), T, null, null);
for (int i = 0; i < 3; i++) {
assertEquals(found.get(i, 3), T_.get(i), 1e-8);
for (int j = 0; j < 3; j++) {
assertEquals(found.get(i, j), R.get(i, j), 1e-8);
}
}
// test uncalibrated camera
found = PerspectiveOps.createCameraMatrix(R.getDDRM(), T, K.getDDRM(), null);
SimpleMatrix expectedR = K.mult(R);
SimpleMatrix expectedT = K.mult(T_);
for (int i = 0; i < 3; i++) {
assertEquals(found.get(i, 3), expectedT.get(i), 1e-8);
for (int j = 0; j < 3; j++) {
assertEquals(found.get(i, j), expectedR.get(i, j), 1e-8);
}
}
}
Aggregations