use of boofcv.alg.distort.LensDistortionNarrowFOV in project BoofCV by lessthanoptimal.
the class TestQuadPoseEstimator method estimateP3P.
@Test
public void estimateP3P() {
LensDistortionNarrowFOV distortion = createDistortion();
Se3_F64 fiducialToCamera = new Se3_F64();
fiducialToCamera.getT().set(0.2, -0.15, 2);
ConvertRotation3D_F64.eulerToMatrix(EulerType.XYZ, 0.05, 0.015, 0.001, fiducialToCamera.R);
QuadPoseEstimator alg = new QuadPoseEstimator(1e-8, 200);
alg.setLensDistoriton(distortion);
double r = 1.5;
alg.setFiducial(r, -r, r, r, -r, r, -r, -r);
WorldToCameraToPixel worldToPixel = PerspectiveOps.createWorldToPixel(distortion, fiducialToCamera);
alg.listObs.add(worldToPixel.transform(alg.points.get(0).location));
alg.listObs.add(worldToPixel.transform(alg.points.get(1).location));
alg.listObs.add(worldToPixel.transform(alg.points.get(2).location));
alg.listObs.add(worldToPixel.transform(alg.points.get(3).location));
Point2Transform2_F64 pixelToNorm = distortion.undistort_F64(true, false);
for (int i = 0; i < 4; i++) {
Point2D_F64 pixel = alg.listObs.get(i);
pixelToNorm.compute(pixel.x, pixel.y, alg.points.get(i).observation);
}
for (int i = 0; i < 4; i++) {
alg.bestError = Double.MAX_VALUE;
alg.estimateP3P(i);
assertEquals(0, alg.bestError, 1e-6);
assertTrue(alg.bestPose.T.distance(fiducialToCamera.T) < 1e-6);
assertTrue(MatrixFeatures_DDRM.isIdentical(alg.bestPose.R, fiducialToCamera.R, 1e-6));
}
}
use of boofcv.alg.distort.LensDistortionNarrowFOV in project BoofCV by lessthanoptimal.
the class TestQuadPoseEstimator method basicTest.
@Test
public void basicTest() {
LensDistortionNarrowFOV distortion = createDistortion();
Se3_F64 expectedW2C = new Se3_F64();
expectedW2C.T.set(0.1, -0.05, 4);
ConvertRotation3D_F64.eulerToMatrix(EulerType.XYZ, 0.03, 0, 0, expectedW2C.R);
Quadrilateral_F64 quadPlane = new Quadrilateral_F64(-0.5, 0.5, 0.5, 0.5, 0.5, -0.5, -0.5, -0.5);
Quadrilateral_F64 quadViewed = new Quadrilateral_F64();
project(expectedW2C, quadPlane.a, quadViewed.a);
project(expectedW2C, quadPlane.b, quadViewed.b);
project(expectedW2C, quadPlane.c, quadViewed.c);
project(expectedW2C, quadPlane.d, quadViewed.d);
QuadPoseEstimator alg = new QuadPoseEstimator(1e-8, 200);
alg.setFiducial(-0.5, 0.5, 0.5, 0.5, 0.5, -0.5, -0.5, -0.5);
alg.setLensDistoriton(distortion);
assertTrue(alg.process(quadViewed, false));
Se3_F64 found = alg.getWorldToCamera();
assertTrue(found.T.distance(expectedW2C.T) < 1e-6);
assertTrue(MatrixFeatures_DDRM.isIdentical(found.R, expectedW2C.R, 1e-6));
// project the found markers back onto the marker and see if it returns the expected result
Point2D_F64 foundMarker = new Point2D_F64();
Point2D_F64 pixel = new Point2D_F64();
alg.normToPixel.compute(quadViewed.a.x, quadViewed.a.y, pixel);
alg.pixelToMarker(pixel.x, pixel.y, foundMarker);
assertTrue(foundMarker.distance(-0.5, 0.5) < 1e-6);
alg.normToPixel.compute(quadViewed.b.x, quadViewed.b.y, pixel);
alg.pixelToMarker(pixel.x, pixel.y, foundMarker);
assertTrue(foundMarker.distance(0.5, 0.5) < 1e-6);
alg.normToPixel.compute(quadViewed.c.x, quadViewed.c.y, pixel);
alg.pixelToMarker(pixel.x, pixel.y, foundMarker);
assertTrue(foundMarker.distance(0.5, -0.5) < 1e-6);
alg.normToPixel.compute(quadViewed.d.x, quadViewed.d.y, pixel);
alg.pixelToMarker(pixel.x, pixel.y, foundMarker);
assertTrue(foundMarker.distance(-0.5, -0.5) < 1e-6);
}
use of boofcv.alg.distort.LensDistortionNarrowFOV in project BoofCV by lessthanoptimal.
the class GenericFiducialDetectorChecks method checkImageLocation.
@Test
public void checkImageLocation() {
for (ImageType type : types) {
ImageBase image = loadImage(type);
FiducialDetector detector = createDetector(type);
// It's not specified if the center should be undistorted or distorted. Just make it easier by
// using undistorted
LensDistortionNarrowFOV distortion = loadDistortion(false);
detector.setLensDistortion(distortion, image.width, image.height);
detector.detect(image);
assertTrue(detector.totalFound() >= 1);
assertTrue(detector.is3D());
for (int i = 0; i < detector.totalFound(); i++) {
Se3_F64 fidToCam = new Se3_F64();
Point2D_F64 found = new Point2D_F64();
detector.getFiducialToCamera(i, fidToCam);
detector.getCenter(i, found);
Point2D_F64 rendered = new Point2D_F64();
WorldToCameraToPixel worldToPixel = PerspectiveOps.createWorldToPixel(distortion, fidToCam);
worldToPixel.transform(new Point3D_F64(0, 0, 0), rendered);
// see if the reprojected is near the pixel location
assertTrue(rendered.distance(found) <= pixelAndProjectedTol);
}
}
}
use of boofcv.alg.distort.LensDistortionNarrowFOV in project BoofCV by lessthanoptimal.
the class SimulatePlanarWorld method setCamera.
public void setCamera(CameraPinholeRadial model) {
output.reshape(model.width, model.height);
depthMap.reshape(model.width, model.height);
LensDistortionNarrowFOV factory = new LensDistortionRadialTangential(model);
pixelTo3 = new NarrowPixelToSphere_F64(factory.undistort_F64(true, false));
sphereToPixel = new SphereToNarrowPixel_F64(factory.distort_F64(false, true));
computeProjectionTable(model);
}
use of boofcv.alg.distort.LensDistortionNarrowFOV in project BoofCV by lessthanoptimal.
the class TestQuadPoseEstimator method computeErrors.
@Test
public void computeErrors() {
LensDistortionNarrowFOV distortion = createDistortion();
Se3_F64 fiducialToCamera = new Se3_F64();
fiducialToCamera.getT().set(0.2, -0.15, 2);
ConvertRotation3D_F64.eulerToMatrix(EulerType.XYZ, 0.05, 0.015, 0.001, fiducialToCamera.R);
QuadPoseEstimator alg = new QuadPoseEstimator(1e-8, 200);
alg.setLensDistoriton(distortion);
double r = 1.5;
alg.setFiducial(r, -r, r, r, -r, r, -r, -r);
WorldToCameraToPixel worldToPixel = PerspectiveOps.createWorldToPixel(distortion, fiducialToCamera);
for (int i = 0; i < 4; i++) {
Point3D_F64 X = alg.points.get(i).location;
alg.listObs.add(worldToPixel.transform(X));
}
// perfect
assertEquals(0, alg.computeErrors(fiducialToCamera), 1e-8);
// now with known errors
for (int i = 0; i < 4; i++) {
alg.listObs.get(i).x += 1.5;
assertEquals(1.5, alg.computeErrors(fiducialToCamera), 1e-8);
alg.listObs.get(i).x -= 1.5;
}
}
Aggregations