Search in sources :

Example 41 with GrayF32

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

the class TestMultiCameraToEquirectangular method addCamera_implicit_mask.

@Test
public void addCamera_implicit_mask() {
    MultiCameraToEquirectangular<GrayF32> alg = createAlgorithm();
    alg.addCamera(new Se3_F32(), new HelperDistortion(), inputWidth, inputHeight);
    MultiCameraToEquirectangular.Camera c = alg.cameras.get(0);
    // should be masked off by the passed in mask and because values are repeated
    int correct = 0;
    for (int y = 0; y < inputHeight; y++) {
        for (int x = 0; x < inputWidth; x++) {
            if (y < inputHeight / 2 && c.mask.get(x, y) > 0) {
                correct++;
            }
        }
    }
    double found = Math.abs(1.0 - correct / (inputWidth * inputHeight / 2.0));
    assertTrue(found <= 0.05);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) Se3_F32(georegression.struct.se.Se3_F32) Test(org.junit.Test)

Example 42 with GrayF32

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

the class TestDataManipulationOps method normalize.

@Test
public void normalize() {
    GrayF32 original = new GrayF32(30, 20);
    GImageMiscOps.fillUniform(original, rand, -1, 1);
    GrayF32 expected = original.createSameShape();
    GrayF32 found = original.clone();
    float mean = 4.5f;
    float stdev = 1.2f;
    PixelMath.minus(original, mean, expected);
    PixelMath.divide(expected, stdev, expected);
    DataManipulationOps.normalize(found, mean, stdev);
    BoofTesting.assertEquals(expected, found, GrlConstants.TEST_F64);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) Test(org.junit.Test)

Example 43 with GrayF32

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

the class TestDataManipulationOps method imageToTensor_fail.

@Test
public void imageToTensor_fail() {
    Planar<GrayF32> image = new Planar<>(GrayF32.class, 30, 25, 2);
    try {
        DataManipulationOps.imageToTensor(image, new Tensor_F32(2, 25, 30), 0);
        fail("expected exception");
    } catch (RuntimeException ignore) {
    }
    try {
        DataManipulationOps.imageToTensor(image, new Tensor_F32(0, 3, 25, 30), 0);
        fail("expected exception");
    } catch (RuntimeException ignore) {
    }
    try {
        DataManipulationOps.imageToTensor(image, new Tensor_F32(1, 2, 26, 30), 0);
        fail("expected exception");
    } catch (RuntimeException ignore) {
    }
    try {
        DataManipulationOps.imageToTensor(image, new Tensor_F32(1, 2, 25, 31), 0);
        fail("expected exception");
    } catch (RuntimeException ignore) {
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) Planar(boofcv.struct.image.Planar) Tensor_F32(deepboof.tensors.Tensor_F32) Test(org.junit.Test)

Example 44 with GrayF32

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

the class TestImageClassifierVggCifar10 method createClassifier.

@Override
public BaseImageClassifier createClassifier() {
    ImageClassifierVggCifar10 alg = new ImageClassifierVggCifar10();
    alg.stats = new YuvStatistics();
    alg.stats.meanU = 120;
    alg.stats.stdevU = 25;
    alg.stats.meanV = 40;
    alg.stats.stdevV = 10;
    alg.stats.kernel = new double[] { 0.1, 0.5, 0.1 };
    alg.stats.kernelOffset = 1;
    alg.localNorm = new ImageLocalNormalization<>(GrayF32.class, BorderType.EXTENDED);
    alg.kernel = DataManipulationOps.create1D_F32(alg.stats.kernel);
    return alg;
}
Also used : GrayF32(boofcv.struct.image.GrayF32) YuvStatistics(deepboof.models.YuvStatistics)

Example 45 with GrayF32

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

the class CalibrateStereoPlanarGuiApp method process.

public void process(String outputFileName) {
    // displays progress so the impatient don't give up
    final ProcessThread monitor = new ProcessThread();
    monitor.start();
    // load images
    calibrator.reset();
    int N = leftImages.size();
    for (int i = 0; i < N; i++) {
        final BufferedImage leftOrig = media.openImage(leftImages.get(i).getPath());
        final BufferedImage rightOrig = media.openImage(rightImages.get(i).getPath());
        if (leftOrig != null && rightOrig != null) {
            GrayF32 leftInput = ConvertBufferedImage.convertFrom(leftOrig, (GrayF32) null);
            GrayF32 rightInput = ConvertBufferedImage.convertFrom(rightOrig, (GrayF32) null);
            CalibrationObservation calibLeft, calibRight;
            if (!detector.process(leftInput)) {
                System.out.println("Feature detection failed in " + leftImages.get(i));
                continue;
            }
            calibLeft = detector.getDetectedPoints();
            if (!detector.process(rightInput)) {
                System.out.println("Feature detection failed in " + rightImages.get(i));
                continue;
            }
            calibRight = detector.getDetectedPoints();
            calibrator.addPair(calibLeft, calibRight);
            final int number = i;
            SwingUtilities.invokeLater(() -> {
                gui.addPair("Image " + number, leftImages.get(number), rightImages.get(number));
                gui.repaint();
                monitor.setMessage(0, "Image " + number);
            });
        } else {
            System.out.println("Failed to load left  = " + leftImages.get(i));
            System.out.println("Failed to load right = " + rightImages.get(i));
        }
    }
    // SwingUtilities.invokeLater(new Runnable() {
    // public void run() {
    // gui.setObservations(calibrator.getCalibLeft().getObservations(),calibrator.getCalibLeft().getErrors(),
    // calibrator.getCalibRight().getObservations(),calibrator.getCalibRight().getErrors());
    // }});
    // gui.repaint();
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            monitor.setMessage(1, "Estimating Parameters");
        }
    });
    StereoParameters param = calibrator.process();
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            gui.setObservations(calibrator.getCalibLeft().getObservations(), calibrator.getCalibLeft().getErrors(), calibrator.getCalibRight().getObservations(), calibrator.getCalibRight().getErrors());
        }
    });
    gui.repaint();
    // compute stereo rectification
    setRectification(param);
    monitor.stopThread();
    calibrator.printStatistics();
    param.print();
    if (outputFileName != null)
        CalibrationIO.save(param, outputFileName);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) StereoParameters(boofcv.struct.calib.StereoParameters) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) CalibrationObservation(boofcv.alg.geo.calibration.CalibrationObservation)

Aggregations

GrayF32 (boofcv.struct.image.GrayF32)530 Test (org.junit.Test)291 BufferedImage (java.awt.image.BufferedImage)81 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)76 GrayU8 (boofcv.struct.image.GrayU8)49 Planar (boofcv.struct.image.Planar)34 ArrayList (java.util.ArrayList)28 ImageBorder_F32 (boofcv.core.image.border.ImageBorder_F32)20 ImageGray (boofcv.struct.image.ImageGray)20 File (java.io.File)20 CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)19 Se3_F64 (georegression.struct.se.Se3_F64)18 TupleDesc_F64 (boofcv.struct.feature.TupleDesc_F64)17 GrayS8 (boofcv.struct.image.GrayS8)16 ListDisplayPanel (boofcv.gui.ListDisplayPanel)14 PathLabel (boofcv.io.PathLabel)14 Kernel2D_F32 (boofcv.struct.convolve.Kernel2D_F32)13 GrayS16 (boofcv.struct.image.GrayS16)13 GrayS32 (boofcv.struct.image.GrayS32)13 Point2D_F64 (georegression.struct.point.Point2D_F64)13