Search in sources :

Example 1 with LensDistortionNarrowFOV

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));
    }
}
Also used : Point2D_F64(georegression.struct.point.Point2D_F64) LensDistortionNarrowFOV(boofcv.alg.distort.LensDistortionNarrowFOV) Point2Transform2_F64(boofcv.struct.distort.Point2Transform2_F64) WorldToCameraToPixel(boofcv.alg.geo.WorldToCameraToPixel) Se3_F64(georegression.struct.se.Se3_F64) Test(org.junit.Test)

Example 2 with LensDistortionNarrowFOV

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);
}
Also used : Point2D_F64(georegression.struct.point.Point2D_F64) Quadrilateral_F64(georegression.struct.shapes.Quadrilateral_F64) LensDistortionNarrowFOV(boofcv.alg.distort.LensDistortionNarrowFOV) Se3_F64(georegression.struct.se.Se3_F64) Test(org.junit.Test)

Example 3 with LensDistortionNarrowFOV

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);
        }
    }
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) Point2D_F64(georegression.struct.point.Point2D_F64) LensDistortionNarrowFOV(boofcv.alg.distort.LensDistortionNarrowFOV) WorldToCameraToPixel(boofcv.alg.geo.WorldToCameraToPixel) ImageBase(boofcv.struct.image.ImageBase) ImageType(boofcv.struct.image.ImageType) Se3_F64(georegression.struct.se.Se3_F64) Test(org.junit.Test)

Example 4 with LensDistortionNarrowFOV

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);
}
Also used : LensDistortionRadialTangential(boofcv.alg.distort.radtan.LensDistortionRadialTangential) NarrowPixelToSphere_F64(boofcv.alg.distort.NarrowPixelToSphere_F64) LensDistortionNarrowFOV(boofcv.alg.distort.LensDistortionNarrowFOV) SphereToNarrowPixel_F64(boofcv.alg.distort.SphereToNarrowPixel_F64)

Example 5 with LensDistortionNarrowFOV

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;
    }
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) LensDistortionNarrowFOV(boofcv.alg.distort.LensDistortionNarrowFOV) WorldToCameraToPixel(boofcv.alg.geo.WorldToCameraToPixel) Se3_F64(georegression.struct.se.Se3_F64) Test(org.junit.Test)

Aggregations

LensDistortionNarrowFOV (boofcv.alg.distort.LensDistortionNarrowFOV)8 Se3_F64 (georegression.struct.se.Se3_F64)7 Point2D_F64 (georegression.struct.point.Point2D_F64)6 LensDistortionRadialTangential (boofcv.alg.distort.radtan.LensDistortionRadialTangential)4 Test (org.junit.Test)4 WorldToCameraToPixel (boofcv.alg.geo.WorldToCameraToPixel)3 CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)3 GrayF32 (boofcv.struct.image.GrayF32)3 Point3D_F64 (georegression.struct.point.Point3D_F64)3 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)2 Polygon2D_F64 (georegression.struct.shapes.Polygon2D_F64)2 BufferedImage (java.awt.image.BufferedImage)2 File (java.io.File)2 ConfigChessboard (boofcv.abst.fiducial.calib.ConfigChessboard)1 NarrowPixelToSphere_F64 (boofcv.alg.distort.NarrowPixelToSphere_F64)1 SphereToNarrowPixel_F64 (boofcv.alg.distort.SphereToNarrowPixel_F64)1 ConfigFiducialBinary (boofcv.factory.fiducial.ConfigFiducialBinary)1 ConfigFiducialImage (boofcv.factory.fiducial.ConfigFiducialImage)1 MousePauseHelper (boofcv.gui.MousePauseHelper)1 PanelGridPanel (boofcv.gui.PanelGridPanel)1