use of georegression.struct.point.Point3D_F64 in project BoofCV by lessthanoptimal.
the class TestMultiViewOps method canonicalCamera.
@Test
public void canonicalCamera() {
DMatrixRMaj K = PerspectiveOps.calibrationMatrix(200, 250, 0.0, 100, 110);
DMatrixRMaj R = ConvertRotation3D_F64.eulerToMatrix(EulerType.XYZ, 1, 2, -0.5, null);
Vector3D_F64 T = new Vector3D_F64(0.5, 0.7, -0.3);
DMatrixRMaj E = MultiViewOps.createEssential(R, T);
DMatrixRMaj F = MultiViewOps.createFundamental(E, K);
Point3D_F64 e1 = new Point3D_F64();
Point3D_F64 e2 = new Point3D_F64();
CommonOps_DDRM.scale(-2.0 / F.get(0, 1), F);
MultiViewOps.extractEpipoles(F, e1, e2);
DMatrixRMaj P = MultiViewOps.canonicalCamera(F, e2, new Vector3D_F64(1, 1, 1), 2);
// recompose the fundamental matrix using the special equation for canonical cameras
DMatrixRMaj foundF = new DMatrixRMaj(3, 3);
DMatrixRMaj crossEpi = new DMatrixRMaj(3, 3);
GeometryMath_F64.crossMatrix(e2, crossEpi);
DMatrixRMaj M = new DMatrixRMaj(3, 3);
CommonOps_DDRM.extract(P, 0, 3, 0, 3, M, 0, 0);
CommonOps_DDRM.mult(crossEpi, M, foundF);
// see if they are equal up to a scale factor
CommonOps_DDRM.scale(1.0 / foundF.get(0, 1), foundF);
CommonOps_DDRM.scale(1.0 / F.get(0, 1), F);
assertTrue(MatrixFeatures_DDRM.isIdentical(F, foundF, 1e-8));
}
use of georegression.struct.point.Point3D_F64 in project BoofCV by lessthanoptimal.
the class TestMultiViewOps method extractCameraMatrices.
@Test
public void extractCameraMatrices() {
DMatrixRMaj P2 = new DMatrixRMaj(3, 4);
DMatrixRMaj P3 = new DMatrixRMaj(3, 4);
TrifocalTensor input = tensor.copy();
MultiViewOps.extractCameraMatrices(input, P2, P3);
// make sure the input was not modified
for (int i = 0; i < 3; i++) assertTrue(MatrixFeatures_DDRM.isIdentical(tensor.getT(i), input.getT(i), 1e-8));
// Using found camera matrices render the point's location
Point3D_F64 X = new Point3D_F64(0.1, 0.05, 2);
Point2D_F64 x1 = new Point2D_F64(X.x / X.z, X.y / X.z);
Point2D_F64 x2 = PerspectiveOps.renderPixel(P2, X);
Point2D_F64 x3 = PerspectiveOps.renderPixel(P3, X);
// validate correctness by testing a constraint on the points
DMatrixRMaj A = new DMatrixRMaj(3, 3);
MultiViewOps.constraint(tensor, x1, x2, x3, A);
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
assertEquals(0, A.get(i, j), 1e-7);
}
}
}
use of georegression.struct.point.Point3D_F64 in project BoofCV by lessthanoptimal.
the class TestPerspectiveOps method renderPixel_cameramatrix.
@Test
public void renderPixel_cameramatrix() {
Point3D_F64 X = new Point3D_F64(0.1, -0.05, 3);
Se3_F64 worldToCamera = new Se3_F64();
ConvertRotation3D_F64.eulerToMatrix(EulerType.XYZ, 0.1, -0.05, 0.03, worldToCamera.getR());
worldToCamera.getT().set(0.2, 0.01, -0.03);
DMatrixRMaj K = RandomMatrices_DDRM.triangularUpper(3, 0, -1, 1, rand);
Point3D_F64 X_cam = SePointOps_F64.transform(worldToCamera, X, null);
Point2D_F64 found;
DMatrixRMaj P = PerspectiveOps.createCameraMatrix(worldToCamera.R, worldToCamera.T, K, null);
Point2D_F64 expected = new Point2D_F64();
expected.x = X_cam.x / X_cam.z;
expected.y = X_cam.y / X_cam.z;
GeometryMath_F64.mult(K, expected, expected);
found = PerspectiveOps.renderPixel(P, X);
assertEquals(expected.x, found.x, 1e-8);
assertEquals(expected.y, found.y, 1e-8);
}
use of georegression.struct.point.Point3D_F64 in project BoofCV by lessthanoptimal.
the class TestPerspectiveOps method renderPixel_intrinsic.
@Test
public void renderPixel_intrinsic() {
Point3D_F64 X = new Point3D_F64(0.1, -0.05, 3);
CameraPinholeRadial intrinsic = new CameraPinholeRadial(100, 150, 0.1, 120, 209, 500, 600);
double normX = X.x / X.z;
double normY = X.y / X.z;
Point2D_F64 expected = new Point2D_F64();
PerspectiveOps.convertNormToPixel(intrinsic, normX, normY, expected);
Point2D_F64 found = PerspectiveOps.renderPixel(intrinsic, X);
assertEquals(expected.x, found.x, 1e-8);
assertEquals(expected.y, found.y, 1e-8);
}
use of georegression.struct.point.Point3D_F64 in project BoofCV by lessthanoptimal.
the class TestPerspectiveOps method scaleIntrinsic.
@Test
public void scaleIntrinsic() {
Point3D_F64 X = new Point3D_F64(0.1, 0.3, 2);
CameraPinholeRadial param = new CameraPinholeRadial(200, 300, 2, 250, 260, 200, 300);
DMatrixRMaj K = PerspectiveOps.calibrationMatrix(param, (DMatrixRMaj) null);
// find the pixel location in the unscaled image
Point2D_F64 a = PerspectiveOps.renderPixel(new Se3_F64(), K, X);
PerspectiveOps.scaleIntrinsic(param, 0.5);
K = PerspectiveOps.calibrationMatrix(param, (DMatrixRMaj) null);
// find the pixel location in the scaled image
Point2D_F64 b = PerspectiveOps.renderPixel(new Se3_F64(), K, X);
assertEquals(a.x * 0.5, b.x, 1e-8);
assertEquals(a.y * 0.5, b.y, 1e-8);
}
Aggregations