use of georegression.struct.point.Point4D_F64 in project BoofCV by lessthanoptimal.
the class CommonThreeViewHomogenous method createScene.
public void createScene(int numFeatures, boolean planar) {
// randomly generate points in space
if (planar) {
worldPts = CommonHomographyChecks.createRandomPlaneH(rand, 3, numFeatures);
} else {
worldPts = GeoTestingOps.randomPointsH_F64(-1, 1, -1, 1, 2, 4, numFeatures, rand);
}
Se3_F64 motion_0_to_0 = new Se3_F64();
Se3_F64 motion_0_to_1 = SpecialEuclideanOps_F64.eulerXyz(0.01, 0.5, 0.2, 0.1, -0.02, 0.015, null);
Se3_F64 motion_0_to_2 = SpecialEuclideanOps_F64.eulerXyz(0.05, 0.03, 0.53, 0.02, 0.1, -0.01, null);
DMatrixRMaj P0 = PerspectiveOps.createCameraMatrix(motion_0_to_0.R, motion_0_to_0.T, K, null);
DMatrixRMaj P1 = PerspectiveOps.createCameraMatrix(motion_0_to_1.R, motion_0_to_1.T, K, null);
DMatrixRMaj P2 = PerspectiveOps.createCameraMatrix(motion_0_to_2.R, motion_0_to_2.T, K, null);
cameras.clear();
cameras.add(P0);
cameras.add(P1);
cameras.add(P2);
fundamentals.clear();
fundamentals.add(MultiViewOps.createFundamental(motion_0_to_1.R, motion_0_to_1.T, K, K, null));
fundamentals.add(MultiViewOps.createFundamental(motion_0_to_2.R, motion_0_to_2.T, K, K, null));
triples.clear();
pixelsInView[0] = new ArrayList<>();
pixelsInView[1] = new ArrayList<>();
pixelsInView[2] = new ArrayList<>();
Point2D_F64 x0 = new Point2D_F64();
Point2D_F64 x1 = new Point2D_F64();
Point2D_F64 x2 = new Point2D_F64();
for (int i = 0; i < numFeatures; i++) {
Point4D_F64 X = worldPts.get(i);
PerspectiveOps.renderPixel(P0, X, x0);
PerspectiveOps.renderPixel(P1, X, x1);
PerspectiveOps.renderPixel(P2, X, x2);
pixelsInView[0].add(x0.copy());
pixelsInView[1].add(x1.copy());
pixelsInView[2].add(x2.copy());
AssociatedTriple t = new AssociatedTriple();
t.setTo(x0, x1, x2);
triples.add(t);
}
}
use of georegression.struct.point.Point4D_F64 in project BoofCV by lessthanoptimal.
the class TestProjectiveReconstructionByFactorization method perfect_input.
/**
* Perfect observations and perfect input, Output should be just perfect
*/
@Test
void perfect_input() {
int numViews = 8;
int numFeatures = 10;
simulate(numViews, numFeatures, false);
ProjectiveStructureByFactorization alg = new ProjectiveStructureByFactorization();
alg.initialize(features3D.size(), projections.size());
// Perfect depths. It should only need 1 iteration
setPerfectDepths(numFeatures, alg);
// noise free pixel observations too
for (int viewIdx = 0; viewIdx < projections.size(); viewIdx++) {
alg.setPixels(viewIdx, observations.get(viewIdx));
}
assertTrue(alg.process());
DMatrixRMaj P = new DMatrixRMaj(3, 4);
Point4D_F64 X = new Point4D_F64();
for (int viewIdx = 0; viewIdx < numViews; viewIdx++) {
alg.getCameraMatrix(viewIdx, P);
for (int featureIdx = 0; featureIdx < numFeatures; featureIdx++) {
alg.getFeature3D(featureIdx, X);
Point2D_F64 expected = observations.get(viewIdx).get(featureIdx);
Point3D_F64 xh = PerspectiveOps.renderPixel(P, X, (Point3D_F64) null);
Point2D_F64 found = new Point2D_F64(xh.x / xh.z, xh.y / xh.z);
assertTrue(expected.distance(found) < UtilEjml.TEST_F64);
}
}
}
use of georegression.struct.point.Point4D_F64 in project BoofCV by lessthanoptimal.
the class TestTriangulateProjectiveLinearDLT method triangulate_metric_N.
/**
* Create 3 perfect observations and solve for the position. Everything is in metric instead of an arbtirary
* projective frame for ease of testing.
*/
@Test
void triangulate_metric_N() {
createScene();
TriangulateProjectiveLinearDLT alg = new TriangulateProjectiveLinearDLT();
Point4D_F64 found = new Point4D_F64();
alg.triangulate(obsPixels, cameraMatrices, found);
found.x /= found.w;
found.y /= found.w;
found.z /= found.w;
assertEquals(worldPoint.x, found.x, 1e-8);
assertEquals(worldPoint.y, found.y, 1e-8);
assertEquals(worldPoint.z, found.z, 1e-8);
}
use of georegression.struct.point.Point4D_F64 in project BoofCV by lessthanoptimal.
the class TestTriangulateProjectiveLinearDLT method triangulate_projective.
/**
* Test case with a true projective situation
*/
@Test
void triangulate_projective() {
createScene();
TriangulateProjectiveLinearDLT alg = new TriangulateProjectiveLinearDLT();
Point4D_F64 foundX = new Point4D_F64();
alg.triangulate(obsPixels, cameraMatrices, foundX);
// project the found coordinate back on to each image
Point2D_F64 foundPixel = new Point2D_F64();
for (int i = 0; i < cameraMatrices.size(); i++) {
DMatrixRMaj P = cameraMatrices.get(i);
Point2D_F64 expected = obsPixels.get(i);
GeometryMath_F64.mult(P, foundX, foundPixel);
assertEquals(0, expected.distance(foundPixel), UtilEjml.TEST_F64);
}
}
use of georegression.struct.point.Point4D_F64 in project BoofCV by lessthanoptimal.
the class TestTriangulateMetricLinearDLT method triangulate_N.
/**
* Create 3 perfect observations and solve for the position
*/
@Test
void triangulate_N() {
createScene();
TriangulateMetricLinearDLT alg = new TriangulateMetricLinearDLT();
Point4D_F64 found = new Point4D_F64();
alg.triangulate(obsNorm, motionWorldToCamera, found);
assertEquals(worldPoint.x, found.x / found.w, UtilEjml.TEST_F64);
assertEquals(worldPoint.y, found.y / found.w, UtilEjml.TEST_F64);
assertEquals(worldPoint.z, found.z / found.w, UtilEjml.TEST_F64);
}
Aggregations