use of boofcv.struct.calib.CameraPinhole in project BoofCV by lessthanoptimal.
the class TestMultiViewOps method triangulatePoints.
/**
* Construct a scene with perfect observations. See if triangulation returns the same points
*/
@Test
void triangulatePoints() {
CameraPinhole intrinsic = new CameraPinhole(500, 500, 0, 500, 500, 1000, 1000);
List<Point3D_F64> points = UtilPoint3D_F64.random(new Point3D_F64(0, 0, 2), -0.5, 0.5, 100, rand);
Se3_F64 view0_to_view1 = SpecialEuclideanOps_F64.eulerXyz(0.3, 0, 0, 0.1, -0.1, 0, null);
SceneStructureMetric structure = new SceneStructureMetric(false);
SceneObservations observations = new SceneObservations();
observations.initialize(2);
structure.initialize(1, 2, points.size());
structure.setCamera(0, true, intrinsic);
structure.setView(0, 0, true, new Se3_F64());
structure.setView(1, 0, false, view0_to_view1);
SceneObservations.View v0 = observations.getView(0);
SceneObservations.View v1 = observations.getView(1);
for (int i = 0; i < points.size(); i++) {
Point3D_F64 X = points.get(i);
Point2D_F64 p0 = PerspectiveOps.renderPixel(intrinsic, X, null);
Point2D_F64 p1 = PerspectiveOps.renderPixel(view0_to_view1, intrinsic, X, null);
v0.add(i, (float) p0.x, (float) p0.y);
v1.add(i, (float) p1.x, (float) p1.y);
structure.connectPointToView(i, 0);
structure.connectPointToView(i, 1);
}
MultiViewOps.triangulatePoints(structure, observations);
Point3D_F64 X = new Point3D_F64();
for (int i = 0; i < points.size(); i++) {
structure.getPoints().get(i).get(X);
assertEquals(0, points.get(i).distance(X), UtilEjml.TEST_F64_SQ);
}
}
use of boofcv.struct.calib.CameraPinhole in project BoofCV by lessthanoptimal.
the class TestMultiViewOps method intrinsicFromAbsoluteQuadratic.
@Test
void intrinsicFromAbsoluteQuadratic() {
Equation eq = new Equation();
eq.process("K1=[300 1 50;0 310 60; 0 0 1]");
eq.process("K2=[310 1 75;0 310 60; 0 0 1]");
eq.process("p=rand(3,1)");
eq.process("u=-p'*K1");
eq.process("H=[K1 [0;0;0]; u 1]");
// very simplistic P
eq.process("P=K2*[eye(3) [1;2;3]]");
// back to projective
eq.process("P=P*inv(H)");
eq.process("Q=-1.1*H*diag([1 1 1 0])*H'");
DMatrixRMaj P = eq.lookupDDRM("P");
DMatrixRMaj Q = eq.lookupDDRM("Q");
CameraPinhole intrinsic = new CameraPinhole();
MultiViewOps.intrinsicFromAbsoluteQuadratic(Q, P, intrinsic);
assertEquals(310, intrinsic.fx, 1e-6);
assertEquals(310, intrinsic.fy, 1e-6);
assertEquals(75, intrinsic.cx, 1e-6);
assertEquals(60, intrinsic.cy, 1e-6);
assertEquals(1, intrinsic.skew, 1e-6);
}
use of boofcv.struct.calib.CameraPinhole in project BoofCV by lessthanoptimal.
the class TestPerspectiveOps method estimatePinhole.
/**
* Test using a known pinhole model which fits its assumptions perfectly
*/
@Test
void estimatePinhole() {
CameraPinhole expected = new CameraPinhole(500, 550, 0, 600, 700, 1200, 1400);
Point2Transform2_F64 pixelToNorm = new LensDistortionPinhole(expected).distort_F64(true, false);
CameraPinhole found = PerspectiveOps.estimatePinhole(pixelToNorm, expected.width, expected.height);
assertEquals(expected.fx, found.fx, UtilEjml.TEST_F64);
assertEquals(expected.fy, found.fy, UtilEjml.TEST_F64);
assertEquals(expected.cx, found.cx, UtilEjml.TEST_F64);
assertEquals(expected.cy, found.cy, UtilEjml.TEST_F64);
assertEquals(expected.skew, found.skew, UtilEjml.TEST_F64);
assertEquals(expected.width, found.width);
assertEquals(expected.height, found.height);
}
use of boofcv.struct.calib.CameraPinhole in project BoofCV by lessthanoptimal.
the class TestPerspectiveOps method matrixToPinhole_D.
@Test
void matrixToPinhole_D() {
double fx = 1;
double fy = 2;
double skew = 3;
double cx = 4;
double cy = 5;
DMatrixRMaj K = new DMatrixRMaj(3, 3, true, fx, skew, cx, 0, fy, cy, 0, 0, 1);
CameraPinhole ret = PerspectiveOps.matrixToPinhole(K, 100, 200, null);
assertEquals(ret.fx, fx, 1.1);
assertEquals(ret.fy, fy);
assertEquals(ret.skew, skew);
assertEquals(ret.cx, cx);
assertEquals(ret.cy, cy);
assertEquals(100, ret.width);
assertEquals(200, ret.height);
}
use of boofcv.struct.calib.CameraPinhole in project BoofCV by lessthanoptimal.
the class TestPerspectiveOps method guessIntrinsic_two.
@Test
void guessIntrinsic_two() {
double hfov = 30;
double vfov = 35;
CameraPinhole found = PerspectiveOps.createIntrinsic(640, 480, hfov, vfov, null);
assertEquals(UtilAngle.degreeToRadian(hfov), 2.0 * Math.atan(found.cx / found.fx), 1e-6);
assertEquals(UtilAngle.degreeToRadian(vfov), 2.0 * Math.atan(found.cy / found.fy), 1e-6);
}
Aggregations