Search in sources :

Example 16 with CameraPinholeBrown

use of boofcv.struct.calib.CameraPinholeBrown in project BoofCV by lessthanoptimal.

the class GenericFiducialDetectorChecks method checkCenter.

@Test
void checkCenter() {
    // It's not specified if the center should be undistorted or distorted. Just make it easier by
    // using undistorted
    CameraPinholeBrown intrinsic = loadDistortion(false);
    LensDistortionBrown lensDistorted = new LensDistortionBrown(intrinsic);
    for (ImageType type : types) {
        ImageBase image = renderImage(intrinsic, type);
        FiducialDetector detector = createDetector(type);
        detector.setLensDistortion(lensDistorted, image.width, image.height);
        // ShowImages.showBlocking(image, "asdfasdf", 5_000);
        detect(detector, 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(lensDistorted, fidToCam);
            worldToPixel.transform(new Point3D_F64(0, 0, 0), rendered);
            // see if the reprojected is near the pixel location
            assertEquals(0.0, rendered.distance(found), pixelAndProjectedTol);
        }
    }
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) Point2D_F64(georegression.struct.point.Point2D_F64) LensDistortionBrown(boofcv.alg.distort.brown.LensDistortionBrown) 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.jupiter.api.Test)

Example 17 with CameraPinholeBrown

use of boofcv.struct.calib.CameraPinholeBrown in project BoofCV by lessthanoptimal.

the class GenericFiducialDetectorChecks method checkSubImage.

@Test
void checkSubImage() {
    CameraPinholeBrown intrinsic = loadDistortion(true);
    LensDistortionBrown lensDistorted = new LensDistortionBrown(intrinsic);
    for (ImageType type : types) {
        ImageBase image = renderImage(intrinsic, type);
        FiducialDetector detector = createDetector(type);
        detector.setLensDistortion(lensDistorted, image.width, image.height);
        detect(detector, image);
        assertTrue(detector.totalFound() >= 1);
        long[] foundID = new long[detector.totalFound()];
        List<Se3_F64> foundPose = new ArrayList<>();
        for (int i = 0; i < detector.totalFound(); i++) {
            foundID[i] = detector.getId(i);
            Se3_F64 pose = new Se3_F64();
            detector.getFiducialToCamera(i, pose);
            foundPose.add(pose);
        }
        // run it again with a sub-image
        detect(detector, BoofTesting.createSubImageOf(image));
        // see if it produced exactly the same results
        assertEquals(foundID.length, detector.totalFound());
        for (int i = 0; i < detector.totalFound(); i++) {
            assertEquals(foundID[i], detector.getId(i));
            Se3_F64 pose = new Se3_F64();
            detector.getFiducialToCamera(i, pose);
            assertEquals(0, pose.getT().distance(foundPose.get(i).T), 1e-8);
            assertTrue(MatrixFeatures_DDRM.isIdentical(pose.getR(), foundPose.get(i).R, 1e-8));
        }
    }
}
Also used : CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) LensDistortionBrown(boofcv.alg.distort.brown.LensDistortionBrown) ArrayList(java.util.ArrayList) ImageBase(boofcv.struct.image.ImageBase) ImageType(boofcv.struct.image.ImageType) Se3_F64(georegression.struct.se.Se3_F64) Test(org.junit.jupiter.api.Test)

Example 18 with CameraPinholeBrown

use of boofcv.struct.calib.CameraPinholeBrown in project BoofCV by lessthanoptimal.

the class GenericFiducialDetectorChecks method checkMultipleRuns.

@Test
void checkMultipleRuns() {
    CameraPinholeBrown intrinsic = loadDistortion(true);
    LensDistortionBrown lensDistorted = new LensDistortionBrown(intrinsic);
    for (ImageType type : types) {
        ImageBase image = renderImage(intrinsic, type);
        FiducialDetector detector = createDetector(type);
        detector.setLensDistortion(lensDistorted, image.width, image.height);
        detect(detector, image);
        assertTrue(detector.totalFound() >= 1);
        Results results = extractResults(detector);
        // run it again
        detect(detector, image);
        // see if it produced exactly the same results
        assertEquals(results.id.length, detector.totalFound());
        for (int i = 0; i < detector.totalFound(); i++) {
            assertEquals(results.id[i], detector.getId(i));
            Point2D_F64 centerPixel = new Point2D_F64();
            detector.getCenter(i, centerPixel);
            assertEquals(0.0, results.centerPixel.get(i).distance(centerPixel), 1e-8);
            Se3_F64 pose = new Se3_F64();
            detector.getFiducialToCamera(i, pose);
            assertEquals(0, pose.getT().distance(results.pose.get(i).T), 1e-8);
            assertTrue(MatrixFeatures_DDRM.isIdentical(pose.getR(), results.pose.get(i).R, 1e-8));
        }
    }
}
Also used : CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) Point2D_F64(georegression.struct.point.Point2D_F64) LensDistortionBrown(boofcv.alg.distort.brown.LensDistortionBrown) ImageBase(boofcv.struct.image.ImageBase) ImageType(boofcv.struct.image.ImageType) Se3_F64(georegression.struct.se.Se3_F64) Test(org.junit.jupiter.api.Test)

Example 19 with CameraPinholeBrown

use of boofcv.struct.calib.CameraPinholeBrown in project BoofCV by lessthanoptimal.

the class GenericFiducialDetectorChecks method checkHandleNewIntrinsic.

/**
 * Tests several items:
 *
 * 1) Does it properly handle setIntrinsic() being called multiple times
 * 2) Can it handle no distortion
 */
@Test
void checkHandleNewIntrinsic() {
    for (ImageType type : types) {
        // distorted camera model
        CameraPinholeBrown instrinsic = loadDistortion(true);
        LensDistortionBrown distortion = new LensDistortionBrown(instrinsic);
        // render a distorted image
        ImageBase image = renderImage(instrinsic, type);
        // give it an undistored model
        FiducialDetector detector = createDetector(type);
        assertFalse(detector.is3D());
        detector.setLensDistortion(new LensDistortionBrown(loadDistortion(false)), image.width, image.height);
        assertTrue(detector.is3D());
        detect(detector, image);
        // it might not be able to detect the target
        if (detector.totalFound() >= 1) {
            checkBounds(detector);
        }
        // Give it the correct model and this time it should work
        detector.setLensDistortion(distortion, image.width, image.height);
        assertTrue(detector.is3D());
        detect(detector, image);
        checkBounds(detector);
        assertTrue(detector.totalFound() >= 1);
        // Now remove the distortion model
        detector.setLensDistortion(null, image.width, image.height);
        assertFalse(detector.is3D());
        detect(detector, image);
        if (detector.totalFound() >= 1) {
            checkBounds(detector);
        }
    }
}
Also used : CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) LensDistortionBrown(boofcv.alg.distort.brown.LensDistortionBrown) ImageBase(boofcv.struct.image.ImageBase) ImageType(boofcv.struct.image.ImageType) Test(org.junit.jupiter.api.Test)

Example 20 with CameraPinholeBrown

use of boofcv.struct.calib.CameraPinholeBrown in project BoofCV by lessthanoptimal.

the class GenericFiducialDetectorChecks method checkStability.

/**
 * See if the stability estimation is reasonable. First detect targets in the full sized image. Then shrink it
 * by 15% and see if the instability increases. The instability should always increase for smaller objects with
 * the same orientation since the geometry is worse.
 */
@Test
void checkStability() {
    // has to be undistorted otherwise rescaling the image won't work
    CameraPinholeBrown intrinsic = loadDistortion(false);
    LensDistortionBrown lensDistorted = new LensDistortionBrown(intrinsic);
    for (ImageType type : types) {
        ImageBase image = renderImage(intrinsic, type);
        FiducialDetector detector = createDetector(type);
        detector.setLensDistortion(lensDistorted, image.width, image.height);
        // ShowImages.showBlocking(image, "First Detect", 3_000);
        detect(detector, image);
        assertTrue(detector.totalFound() >= 1);
        long[] foundIds = new long[detector.totalFound()];
        double[] location = new double[detector.totalFound()];
        double[] orientation = new double[detector.totalFound()];
        FiducialStability results = new FiducialStability();
        for (int i = 0; i < detector.totalFound(); i++) {
            detector.computeStability(i, 0.2, results);
            foundIds[i] = detector.getId(i);
            location[i] = results.location;
            orientation[i] = results.orientation;
        }
        // by shrinking the image a small pixel error should result
        // in a larger pose error, hence more unstable
        ImageBase shrunk = image.createSameShape();
        new FDistort(image, shrunk).affine(stabilityShrink, 0, 0, stabilityShrink, image.width / 4, image.height / 4).apply();
        // ShowImages.showBlocking(shrunk, "Shrunk", 2_000);
        detect(detector, shrunk);
        assertEquals(detector.totalFound(), foundIds.length);
        for (int i = 0; i < detector.totalFound(); i++) {
            detector.computeStability(i, 0.2, results);
            long id = detector.getId(i);
            boolean matched = false;
            for (int j = 0; j < foundIds.length; j++) {
                if (foundIds[j] == id) {
                    matched = true;
                    assertTrue(location[j] < results.location);
                    assertTrue(orientation[j] < results.orientation);
                    break;
                }
            }
            assertTrue(matched);
        }
    }
}
Also used : CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) FDistort(boofcv.abst.distort.FDistort) LensDistortionBrown(boofcv.alg.distort.brown.LensDistortionBrown) ImageBase(boofcv.struct.image.ImageBase) ImageType(boofcv.struct.image.ImageType) Test(org.junit.jupiter.api.Test)

Aggregations

CameraPinholeBrown (boofcv.struct.calib.CameraPinholeBrown)99 Test (org.junit.jupiter.api.Test)62 Se3_F64 (georegression.struct.se.Se3_F64)39 GrayF32 (boofcv.struct.image.GrayF32)29 Point2D_F64 (georegression.struct.point.Point2D_F64)19 SimulatePlanarWorld (boofcv.simulation.SimulatePlanarWorld)16 LensDistortionBrown (boofcv.alg.distort.brown.LensDistortionBrown)14 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)14 BufferedImage (java.awt.image.BufferedImage)14 ArrayList (java.util.ArrayList)12 CameraPinhole (boofcv.struct.calib.CameraPinhole)11 Point2Transform2_F64 (boofcv.struct.distort.Point2Transform2_F64)10 DMatrixRMaj (org.ejml.data.DMatrixRMaj)10 File (java.io.File)9 StereoParameters (boofcv.struct.calib.StereoParameters)6 GrayU8 (boofcv.struct.image.GrayU8)6 Point3D_F64 (georegression.struct.point.Point3D_F64)6 ImageBase (boofcv.struct.image.ImageBase)5 ImageType (boofcv.struct.image.ImageType)5 DogArray (org.ddogleg.struct.DogArray)5