Search in sources :

Example 31 with ImageBase

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

the class TestCreateSyntheticOverheadView method checkPrecomputedTransform.

@Test
public void checkPrecomputedTransform() {
    // Easier to make up a plane in this direction
    Se3_F64 cameraToPlane = new Se3_F64();
    ConvertRotation3D_F64.eulerToMatrix(EulerType.XYZ, UtilAngle.degreeToRadian(0), 0, 0, cameraToPlane.getR());
    cameraToPlane.getT().set(0, -5, 0);
    Se3_F64 planeToCamera = cameraToPlane.invert(null);
    CreateSyntheticOverheadView alg = new CreateSyntheticOverheadView() {

        @Override
        public void process(ImageBase input, ImageBase output) {
        }
    };
    int overheadW = 500;
    int overheadH = 600;
    double cellSize = 0.05;
    double centerX = 1;
    double centerY = overheadH * cellSize / 2.0;
    alg.configure(param, planeToCamera, centerX, centerY, cellSize, overheadW, overheadH);
    // directly below camera, should not be in view
    assertTrue(null == alg.getOverheadToPixel(0, 300));
    // point at the end of the map should be in view
    assertTrue(null != alg.getOverheadToPixel(overheadW - 1, 300));
    // check the value at one point by doing the reverse transform
    Point2D_F32 found = alg.getOverheadToPixel(400, 320);
    CameraPlaneProjection proj = new CameraPlaneProjection();
    proj.setPlaneToCamera(planeToCamera, true);
    proj.setIntrinsic(param);
    Point2D_F64 expected = new Point2D_F64();
    proj.pixelToPlane(found.x, found.y, expected);
    // put into overhead pixels
    expected.x = (expected.x + centerX) / cellSize;
    expected.y = (expected.y + centerY) / cellSize;
    assertEquals(400, expected.x, 1e-4);
    assertEquals(320, expected.y, 1e-4);
}
Also used : Point2D_F64(georegression.struct.point.Point2D_F64) Point2D_F32(georegression.struct.point.Point2D_F32) ImageBase(boofcv.struct.image.ImageBase) Se3_F64(georegression.struct.se.Se3_F64) Test(org.junit.Test)

Example 32 with ImageBase

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

the class BatchDownSizeImage method main.

public static void main(String[] args) {
    parseArguments(args);
    ImageBase input = new GrayU8(1, 1);
    ImageBase small = null;
    int index = 0;
    int numDigits = BoofMiscOps.numDigits(images.size() - 1);
    String format = "%" + numDigits + "d";
    String format0 = "%0" + numDigits + "d";
    for (File f : images) {
        BufferedImage orig = UtilImageIO.loadImage(f.getPath());
        WritableRaster info = orig.getRaster();
        boolean missMatch = false;
        if (input.getWidth() != info.getWidth() || input.getHeight() != info.getHeight()) {
            missMatch = true;
        }
        if (info.getNumBands() == 1) {
            if (!(input instanceof ImageGray))
                missMatch = true;
        } else {
            if (!(input instanceof Planar)) {
                missMatch = true;
            } else if (info.getNumBands() != ((Planar) input).getNumBands()) {
                missMatch = true;
            }
        }
        if (missMatch) {
            // declare the BoofCV image to conver the input into
            if (info.getNumBands() == 1) {
                input = new GrayU8(info.getWidth(), info.getHeight());
            } else {
                input = new Planar<>(GrayU8.class, info.getWidth(), info.getHeight(), info.getNumBands());
            }
            // Now declare storage for the small image
            int smallHeight, smallWidth;
            if (useSide) {
                if (input.getWidth() > input.getHeight()) {
                    width = side;
                    height = 0;
                } else {
                    height = side;
                    width = 0;
                }
            }
            if (height == 0) {
                smallWidth = width;
                smallHeight = input.getHeight() * width / input.getWidth();
            } else if (width == 0) {
                smallWidth = input.getWidth() * height / input.getHeight();
                smallHeight = height;
            } else {
                smallWidth = width;
                smallHeight = height;
            }
            small = input.createNew(smallWidth, smallHeight);
        }
        System.out.printf(" " + format + " out of " + format + "   %s\n", index + 1, images.size(), f.getName());
        ConvertBufferedImage.convertFrom(orig, input, true);
        AverageDownSampleOps.down(input, small);
        String nout;
        if (rename) {
            nout = String.format("image" + format0 + ".png", index);
        } else {
            nout = f.getName();
            nout = nout.substring(0, nout.length() - 3) + "png";
        }
        File fout = new File(outputDir, nout);
        UtilImageIO.saveImage(small, fout.getPath());
        index++;
    }
    System.out.println("Done");
}
Also used : WritableRaster(java.awt.image.WritableRaster) Planar(boofcv.struct.image.Planar) GrayU8(boofcv.struct.image.GrayU8) ImageGray(boofcv.struct.image.ImageGray) File(java.io.File) ImageBase(boofcv.struct.image.ImageBase) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 33 with ImageBase

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

the class CompareIdenticalFunctions method compareResults.

@Override
protected void compareResults(Object targetResult, Object[] targetParam, Object validationResult, Object[] validationParam) {
    for (int i = 0; i < targetParam.length; i++) {
        if (!ImageBase.class.isAssignableFrom(targetParam[i].getClass()))
            continue;
        ImageBase t = (ImageBase) targetParam[i];
        ImageBase v = (ImageBase) validationParam[i];
        // todo is this tolerance too big?  some operations with a slightly different ordering seem to require it
        BoofTesting.assertEqualsRelative(v, t, 1e-4);
    }
}
Also used : ImageBase(boofcv.struct.image.ImageBase)

Example 34 with ImageBase

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

the class TestBlurStorageFilter method median.

@Test
public void median() {
    for (ImageType c : imageTypes) {
        ImageBase input = c.createImage(width, height);
        ImageBase found = c.createImage(width, height);
        ImageBase expected = c.createImage(width, height);
        GImageMiscOps.fillUniform(input, rand, 0, 100);
        BlurStorageFilter alg = new BlurStorageFilter<>("median", c, 2);
        GBlurImageOps.median(input, found, 2);
        alg.process(input, expected);
        BoofTesting.assertEquals(expected, found, 1e-4);
    }
}
Also used : ImageBase(boofcv.struct.image.ImageBase) ImageType(boofcv.struct.image.ImageType) Test(org.junit.Test)

Example 35 with ImageBase

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

the class TestBlurStorageFilter method mean.

@Test
public void mean() {
    for (ImageType c : imageTypes) {
        ImageBase input = c.createImage(width, height);
        ImageBase found = c.createImage(width, height);
        ImageBase expected = c.createImage(width, height);
        ImageBase storage = c.createImage(width, height);
        GImageMiscOps.fillUniform(input, rand, 0, 100);
        BlurStorageFilter alg = new BlurStorageFilter<>("mean", c, 2);
        GBlurImageOps.mean(input, found, 2, storage);
        alg.process(input, expected);
        BoofTesting.assertEquals(expected, found, 1e-4);
    }
}
Also used : ImageBase(boofcv.struct.image.ImageBase) ImageType(boofcv.struct.image.ImageType) Test(org.junit.Test)

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