Search in sources :

Example 16 with ImageType

use of boofcv.struct.image.ImageType 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 17 with ImageType

use of boofcv.struct.image.ImageType in project BoofCV by lessthanoptimal.

the class GenericFiducialDetectorChecks method checkMultipleRuns.

@Test
public void checkMultipleRuns() {
    for (ImageType type : types) {
        ImageBase image = loadImage(type);
        FiducialDetector detector = createDetector(type);
        detector.setLensDistortion(loadDistortion(true), image.width, image.height);
        detector.detect(image);
        assertTrue(detector.totalFound() >= 1);
        Results results = extractResults(detector);
        // run it again
        detector.detect(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));
            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 : ImageBase(boofcv.struct.image.ImageBase) ImageType(boofcv.struct.image.ImageType) Se3_F64(georegression.struct.se.Se3_F64) Test(org.junit.Test)

Example 18 with ImageType

use of boofcv.struct.image.ImageType 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
public void checkStability() {
    for (ImageType type : types) {
        ImageBase image = loadImage(type);
        FiducialDetector detector = createDetector(type);
        detector.setLensDistortion(loadDistortion(true), image.width, image.height);
        detector.detect(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;
        }
        ImageBase shrunk = image.createSameShape();
        new FDistort(image, shrunk).affine(0.8, 0, 0, 0.8, 0, 0).apply();
        detector.detect(shrunk);
        assertTrue(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 : FDistort(boofcv.abst.distort.FDistort) ImageBase(boofcv.struct.image.ImageBase) ImageType(boofcv.struct.image.ImageType) Test(org.junit.Test)

Example 19 with ImageType

use of boofcv.struct.image.ImageType 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
public void checkHandleNewIntrinsic() {
    for (ImageType type : types) {
        ImageBase image = loadImage(type);
        FiducialDetector detector = createDetector(type);
        detector.setLensDistortion(loadDistortion(true), image.width, image.height);
        detector.detect(image);
        assertTrue(detector.totalFound() >= 1);
        checkBounds(detector);
        Results results = extractResults(detector);
        // run it again with a changed intrinsic that's incorrect
        detector.setLensDistortion(loadDistortion(false), image.width, image.height);
        detector.detect(image);
        checkBounds(detector);
        // results should have changed
        if (results.id.length == detector.totalFound()) {
            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();
                Point2D_F64 pixel = new Point2D_F64();
                detector.getFiducialToCamera(i, pose);
                detector.getCenter(i, pixel);
                assertTrue(pose.getT().distance(results.pose.get(i).T) > 1e-4);
                assertFalse(MatrixFeatures_DDRM.isIdentical(pose.getR(), results.pose.get(i).R, 1e-4));
                // pixel location is based on the observed location, thus changing the intrinsics should not
                // affect it
                assertTrue(results.pixel.get(i).distance(pixel) <= 2.0);
            }
        } else {
        // clearly changed
        }
        // then reproduce original
        detector.setLensDistortion(loadDistortion(true), image.width, image.height);
        detector.detect(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));
            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 : Point2D_F64(georegression.struct.point.Point2D_F64) ImageBase(boofcv.struct.image.ImageBase) ImageType(boofcv.struct.image.ImageType) Se3_F64(georegression.struct.se.Se3_F64) Test(org.junit.Test)

Example 20 with ImageType

use of boofcv.struct.image.ImageType in project BoofCV by lessthanoptimal.

the class GenericFiducialDetectorChecks method checkSubImage.

@Test
public void checkSubImage() {
    for (ImageType type : types) {
        ImageBase image = loadImage(type);
        FiducialDetector detector = createDetector(type);
        detector.setLensDistortion(loadDistortion(true), image.width, image.height);
        detector.detect(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
        detector.detect(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 : ArrayList(java.util.ArrayList) ImageBase(boofcv.struct.image.ImageBase) ImageType(boofcv.struct.image.ImageType) Se3_F64(georegression.struct.se.Se3_F64) Test(org.junit.Test)

Aggregations

ImageType (boofcv.struct.image.ImageType)36 Test (org.junit.Test)19 ImageBase (boofcv.struct.image.ImageBase)14 ArrayList (java.util.ArrayList)11 File (java.io.File)10 PathLabel (boofcv.io.PathLabel)7 BackgroundModelMoving (boofcv.alg.background.BackgroundModelMoving)4 Homography2D_F32 (georegression.struct.homography.Homography2D_F32)4 Se3_F64 (georegression.struct.se.Se3_F64)4 BufferedImage (java.awt.image.BufferedImage)4 GrayU8 (boofcv.struct.image.GrayU8)3 BackgroundModelStationary (boofcv.alg.background.BackgroundModelStationary)2 ConfigBackgroundBasic (boofcv.factory.background.ConfigBackgroundBasic)2 ConfigBackgroundGaussian (boofcv.factory.background.ConfigBackgroundGaussian)2 ConfigBackgroundGmm (boofcv.factory.background.ConfigBackgroundGmm)2 ImageGridPanel (boofcv.gui.image.ImageGridPanel)2 MediaManager (boofcv.io.MediaManager)2 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)2 SimpleImageSequence (boofcv.io.image.SimpleImageSequence)2 DefaultMediaManager (boofcv.io.wrapper.DefaultMediaManager)2