use of boofcv.struct.calib.CameraPinhole in project BoofCV by lessthanoptimal.
the class TestRefineDualQuadraticAlgebraicError method solveFixedAspect.
@Test
void solveFixedAspect() {
List<CameraPinhole> expected = new ArrayList<>();
List<CameraPinhole> found = new ArrayList<>();
for (int i = 0; i < 30; i++) {
expected.add(new CameraPinhole(400 + i * 5, 420, 0.0, 410, 420, 0, 0));
found.add(new CameraPinhole(expected.get(i)));
double scaleF = 1.0 + (rand.nextDouble() - 0.5) / 10.0;
found.get(i).fx *= scaleF;
found.get(i).fy *= scaleF;
found.get(i).cx += 2 * rand.nextGaussian();
found.get(i).cy += 2 * rand.nextGaussian();
}
var alg = new RefineDualQuadraticAlgebraicError();
alg.setKnownAspect(true);
checkRefine(alg, expected, found, 5);
}
use of boofcv.struct.calib.CameraPinhole in project BoofCV by lessthanoptimal.
the class TestRefineDualQuadraticAlgebraicError method checkRefine.
private void checkRefine(RefineDualQuadraticAlgebraicError alg, List<CameraPinhole> expected, List<CameraPinhole> noisy, double tol) {
// alg.setVerbose(System.out, null);
renderGood(expected);
setState(alg, noisy, planeAtInfinity.get(0), planeAtInfinity.get(1), planeAtInfinity.get(2));
assertTrue(alg.refine());
List<CameraState> found = alg.getCameras().toList();
// checking against size of noisy, since noisy is number of cameras
assertEquals(noisy.size(), found.size());
// estimate gets worse
for (int i = 0; i < noisy.size(); i++) {
CameraPinhole e = expected.get(i);
CameraState f = found.get(i);
if (alg.isKnownAspect()) {
assertEquals(e.fx, f.fx, tol);
assertEquals(e.fy / e.fx, f.aspectRatio, 0.01);
} else {
assertEquals(e.fx, f.fx, tol);
assertEquals(e.fy / e.fx, f.aspectRatio, 0.05);
}
if (alg.isKnownPrinciplePoint()) {
assertEquals(e.cx, f.cx, UtilEjml.TEST_F64_SQ);
assertEquals(e.cy, f.cy, UtilEjml.TEST_F64_SQ);
} else {
assertEquals(e.cx, f.cx, tol);
assertEquals(e.cy, f.cy, tol);
}
}
}
use of boofcv.struct.calib.CameraPinhole in project BoofCV by lessthanoptimal.
the class TestSelfCalibrationLinearRotationMulti method convertW.
@Test
void convertW() {
double tol = 0.001;
Homography2D_F64 K = new Homography2D_F64(300, 1, 320, 0, 305, 330, 0, 0, 1);
Homography2D_F64 W = new Homography2D_F64();
CommonOps_DDF3.multTransB(K, K, W);
CommonOps_DDF3.invert(W, W);
CameraPinhole found = new CameraPinhole();
SelfCalibrationLinearRotationMulti alg = new SelfCalibrationLinearRotationMulti();
alg.setConstraints(false, false, false, -1);
alg.convertW(W, found);
assertEquals(K.a11, found.fx, tol);
assertEquals(K.a12, found.skew, tol);
assertEquals(K.a13, found.cx, tol);
assertEquals(K.a22, found.fy, tol);
assertEquals(K.a23, found.cy, tol);
// Add zero Skew
K.a12 = 0;
CommonOps_DDF3.multTransB(K, K, W);
CommonOps_DDF3.invert(W, W);
alg.setConstraints(true, false, false, -1);
alg.convertW(W, found);
assertEquals(K.a11, found.fx, tol);
assertEquals(0, found.skew, tol);
assertEquals(K.a13, found.cx, tol);
assertEquals(K.a22, found.fy, tol);
assertEquals(K.a23, found.cy, tol);
// Add origin at zero
K.a13 = K.a23 = 0;
CommonOps_DDF3.multTransB(K, K, W);
CommonOps_DDF3.invert(W, W);
alg.setConstraints(true, true, false, -1);
alg.convertW(W, found);
assertEquals(K.a11, found.fx, tol);
assertEquals(0, found.skew, tol);
assertEquals(0, found.cx, tol);
assertEquals(K.a22, found.fy, tol);
assertEquals(0, found.cy, tol);
// Add known aspect ratio
double aspect = K.a22 / K.a11;
CommonOps_DDF3.multTransB(K, K, W);
CommonOps_DDF3.invert(W, W);
alg.setConstraints(true, true, true, aspect);
alg.convertW(W, found);
assertEquals(K.a11, found.fx, tol);
assertEquals(0, found.skew, tol);
assertEquals(0, found.cx, tol);
assertEquals(K.a22, found.fy, tol);
assertEquals(0, found.cy, tol);
// sanity check. give it a bad skew and see what happens
alg.setConstraints(true, true, true, aspect * aspect);
alg.convertW(W, found);
assertTrue(Math.abs(K.a22 - found.fy) > tol);
}
use of boofcv.struct.calib.CameraPinhole in project BoofCV by lessthanoptimal.
the class TestSelfCalibrationLinearRotationMulti method before.
@BeforeEach
public void before() {
camera = new CameraPinhole(400, 410, 0, 500, 520, 0, 0);
PerspectiveOps.pinholeToMatrix(camera, K);
}
use of boofcv.struct.calib.CameraPinhole in project BoofCV by lessthanoptimal.
the class TestSelfCalibrationLinearRotationMulti method perfect_AllLinear.
@Test
void perfect_AllLinear() {
// set the principle point to zero
camera = new CameraPinhole(400, 420, 0, 510, 540, 0, 0);
PerspectiveOps.pinholeToMatrix(camera, K);
renderRotationOnly(camera);
List<Homography2D_F64> viewsI_to_view0 = computeHomographies();
SelfCalibrationLinearRotationMulti alg = new SelfCalibrationLinearRotationMulti();
alg.setConstraints(true, false, true, camera.fy / camera.fx);
assertSame(alg.estimate(viewsI_to_view0), GeometricResult.SUCCESS);
DogArray<CameraPinhole> found = alg.getFound();
for (int i = 0; i < found.size; i++) {
CameraPinhole f = found.get(i);
assertEquals(camera.fx, f.fx, UtilEjml.TEST_F64);
assertEquals(camera.fy, f.fy, UtilEjml.TEST_F64);
assertEquals(camera.skew, f.skew, UtilEjml.TEST_F64);
assertEquals(camera.cx, f.cx, UtilEjml.TEST_F64);
assertEquals(camera.cy, f.cy, UtilEjml.TEST_F64);
}
}
Aggregations