Search in sources :

Example 26 with ImageBase

use of boofcv.struct.image.ImageBase 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 27 with ImageBase

use of boofcv.struct.image.ImageBase 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 28 with ImageBase

use of boofcv.struct.image.ImageBase 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 29 with ImageBase

use of boofcv.struct.image.ImageBase 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)

Example 30 with ImageBase

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

the class DemonstrationBase method openImage.

protected void openImage(boolean reopen, String filePath, BufferedImage buffered) {
    synchronized (lockStartingProcess) {
        if (startingProcess) {
            System.out.println("Ignoring image request.  Detected spamming");
            return;
        }
        startingProcess = true;
    }
    synchronized (inputStreams) {
        if (inputStreams.size() != 1)
            throw new IllegalArgumentException("Input streams not equal to 1.  Override openImage()");
    }
    stopAllInputProcessing();
    synchronized (inputStreams) {
        inputMethod = InputMethod.IMAGE;
        // copy the image into the cache
        CacheSequenceStream cache = inputStreams.get(0);
        cache.reset();
        ImageBase boof = cache.getBoofImage();
        boof.reshape(buffered.getWidth(), buffered.getHeight());
        ConvertBufferedImage.convertFrom(buffered, boof, true);
        cache.setBufferedImage(buffered);
        if (threadProcess != null)
            throw new RuntimeException("There was still an active stream thread!");
        threadProcess = new ProcessImageThread();
    }
    if (!reopen) {
        setInputName(new File(filePath).getName());
        handleInputChange(0, inputMethod, buffered.getWidth(), buffered.getHeight());
    }
    threadProcess.start();
}
Also used : File(java.io.File) ImageBase(boofcv.struct.image.ImageBase)

Aggregations

ImageBase (boofcv.struct.image.ImageBase)54 ImageType (boofcv.struct.image.ImageType)14 Test (org.junit.Test)13 Se3_F64 (georegression.struct.se.Se3_F64)5 BufferedImage (java.awt.image.BufferedImage)5 SimpleImageSequence (boofcv.io.image.SimpleImageSequence)4 GrayU8 (boofcv.struct.image.GrayU8)4 MediaManager (boofcv.io.MediaManager)3 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)3 DefaultMediaManager (boofcv.io.wrapper.DefaultMediaManager)3 KernelBase (boofcv.struct.convolve.KernelBase)3 Point2D_F64 (georegression.struct.point.Point2D_F64)3 ConfigBackgroundBasic (boofcv.factory.background.ConfigBackgroundBasic)2 ConfigBackgroundGmm (boofcv.factory.background.ConfigBackgroundGmm)2 ImageGridPanel (boofcv.gui.image.ImageGridPanel)2 ImagePanel (boofcv.gui.image.ImagePanel)2 GrayF32 (boofcv.struct.image.GrayF32)2 Planar (boofcv.struct.image.Planar)2 File (java.io.File)2 FDistort (boofcv.abst.distort.FDistort)1