Search in sources :

Example 6 with LensDistortionBrown

use of boofcv.alg.distort.brown.LensDistortionBrown in project BoofCV by lessthanoptimal.

the class GenericFiducialDetectorChecks method checkPoseWithAndWithOutDistortion.

/**
 * Give it an undistorted image. See if it can detect the target. Now give it an distorted image with
 * lens parameters and see if it produces the same solution
 */
@Test
void checkPoseWithAndWithOutDistortion() {
    LensDistortionBrown lensDistorted = new LensDistortionBrown(loadDistortion(true));
    LensDistortionBrown lensUndistorted = new LensDistortionBrown(loadDistortion(false));
    for (ImageType type : types) {
        // render an undistorted image
        ImageBase imageUn = renderImage(loadDistortion(false), type);
        // ShowImages.showWindow(imageUn,"adsasdf");
        // BoofMiscOps.sleep(10000);
        FiducialDetector detector = createDetector(type);
        detector.setLensDistortion(lensUndistorted, imageUn.width, imageUn.height);
        detect(detector, imageUn);
        assertTrue(detector.totalFound() >= 1);
        Results results = extractResults(detector);
        // feed it a distorted with and give the detector the undistortion model
        ImageBase imageD = renderImage(loadDistortion(true), type);
        detector.setLensDistortion(lensDistorted, imageD.width, imageD.height);
        detect(detector, imageD);
        // see if the results are the same
        assertEquals(results.id.length, detector.totalFound());
        for (int i = 0; i < detector.totalFound(); i++) {
            assertEquals(results.id[i], detector.getId(i));
            Se3_F64 pose = new Se3_F64();
            detector.getFiducialToCamera(i, pose);
            // make the error relative to the translation
            double t = pose.getT().norm();
            assertEquals(0, pose.getT().distance(results.pose.get(i).T), t * 0.01);
            assertTrue(MatrixFeatures_DDRM.isIdentical(pose.getR(), results.pose.get(i).R, 0.01));
        }
    }
}
Also used : 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 7 with LensDistortionBrown

use of boofcv.alg.distort.brown.LensDistortionBrown 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 8 with LensDistortionBrown

use of boofcv.alg.distort.brown.LensDistortionBrown 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 9 with LensDistortionBrown

use of boofcv.alg.distort.brown.LensDistortionBrown 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 10 with LensDistortionBrown

use of boofcv.alg.distort.brown.LensDistortionBrown 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

LensDistortionBrown (boofcv.alg.distort.brown.LensDistortionBrown)25 CameraPinholeBrown (boofcv.struct.calib.CameraPinholeBrown)14 Se3_F64 (georegression.struct.se.Se3_F64)13 Test (org.junit.jupiter.api.Test)10 ImageBase (boofcv.struct.image.ImageBase)9 ImageType (boofcv.struct.image.ImageType)9 Point2Transform2_F64 (boofcv.struct.distort.Point2Transform2_F64)8 GrayF32 (boofcv.struct.image.GrayF32)8 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)7 BufferedImage (java.awt.image.BufferedImage)7 Point2D_F64 (georegression.struct.point.Point2D_F64)6 LensDistortionNarrowFOV (boofcv.alg.distort.LensDistortionNarrowFOV)4 ListDisplayPanel (boofcv.gui.ListDisplayPanel)4 Point3D_F64 (georegression.struct.point.Point3D_F64)4 PointToPixelTransform_F64 (boofcv.struct.distort.PointToPixelTransform_F64)3 GrayU8 (boofcv.struct.image.GrayU8)3 Polygon2D_F64 (georegression.struct.shapes.Polygon2D_F64)3 File (java.io.File)3 FoundFiducial (boofcv.alg.fiducial.square.FoundFiducial)2 ConfigPolygonDetector (boofcv.factory.shape.ConfigPolygonDetector)2