Search in sources :

Example 66 with Planar

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

the class TestComputeRegionMeanColor method specific_PL_F32.

@Test
public void specific_PL_F32() {
    createRegionColor(2);
    GrayF32 band = new GrayF32(w, h);
    float a = 1.1f, b = 2.2f, c = 3.3f, d = 10.7f;
    float[] expected = new float[] { a, b, c, d };
    band.data = new float[] { a, a, a, a, a, b, b, b, b, b, c, c, c, c, c, d, d, d, d, d };
    Planar<GrayF32> image = new Planar<>(GrayF32.class, w, h, 2);
    image.bands[0] = band;
    image.bands[1] = band;
    ComputeRegionMeanColor<Planar<GrayF32>> alg = new ComputeRegionMeanColor.PL_F32(2);
    alg.process(image, segments, regionMemberCount, regionColor);
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 2; j++) {
            assertEquals(expected[i], regionColor.get(i)[j], 1e-4f);
        }
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) Planar(boofcv.struct.image.Planar) Test(org.junit.Test)

Example 67 with Planar

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

the class TestComputeRegionMeanColor method specific_PL_U8.

@Test
public void specific_PL_U8() {
    createRegionColor(2);
    GrayU8 band = new GrayU8(w, h);
    byte a = 1, b = 2, c = 3, d = 10;
    byte[] expected = new byte[] { a, b, c, d };
    band.data = new byte[] { a, a, a, a, a, b, b, b, b, b, c, c, c, c, c, d, d, d, d, d };
    Planar<GrayU8> image = new Planar<>(GrayU8.class, w, h, 2);
    image.bands[0] = band;
    image.bands[1] = band;
    ComputeRegionMeanColor<Planar<GrayU8>> alg = new ComputeRegionMeanColor.PL_U8(2);
    alg.process(image, segments, regionMemberCount, regionColor);
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 2; j++) {
            assertEquals(expected[i], regionColor.get(i)[j], 1e-4f);
        }
    }
}
Also used : Planar(boofcv.struct.image.Planar) GrayU8(boofcv.struct.image.GrayU8) Test(org.junit.Test)

Example 68 with Planar

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

the class TestGradientReduceToSingle method maxf_plf32_f32.

@Test
public void maxf_plf32_f32() {
    Planar<GrayF32> inX = new Planar<>(GrayF32.class, width, height, numbands);
    Planar<GrayF32> inY = new Planar<>(GrayF32.class, width, height, numbands);
    GrayF32 outX = new GrayF32(width, height);
    GrayF32 outY = new GrayF32(width, height);
    GImageMiscOps.fillUniform(inX, rand, 0, 100);
    GImageMiscOps.fillUniform(inY, rand, 0, 100);
    GradientReduceToSingle.maxf(inX, inY, outX, outY);
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            float maxNorm = 0;
            float maxValueX = -Float.MAX_VALUE;
            float maxValueY = -Float.MAX_VALUE;
            for (int i = 0; i < numbands; i++) {
                float dx = inX.getBand(i).get(x, y);
                float dy = inY.getBand(i).get(x, y);
                float r = dx * dx + dy * dy;
                if (r > maxNorm) {
                    maxNorm = r;
                    maxValueX = dx;
                    maxValueY = dy;
                }
            }
            assertEquals(maxValueX, outX.get(x, y), 1e-4f);
            assertEquals(maxValueY, outY.get(x, y), 1e-4f);
        }
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) Planar(boofcv.struct.image.Planar) Test(org.junit.Test)

Example 69 with Planar

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

the class TestVisOdomDirectColorDepth method computeMotion.

public Se3_F32 computeMotion(float colorBefore, float colorAfter, float dx, float dy) {
    VisOdomDirectColorDepth<GrayF32, GrayF32> alg = new VisOdomDirectColorDepth<>(numBands, imageType, imageType);
    alg.setCameraParameters(fx, fy, cx, cy, width, height);
    Planar<GrayF32> input = new Planar<>(GrayF32.class, width, height, numBands);
    GImageMiscOps.fill(input, colorAfter);
    alg.initMotion(input);
    GImageMiscOps.fill(alg.derivX, dx);
    GImageMiscOps.fill(alg.derivY, dy);
    // need to add noise to avoid pathological stuff
    GImageMiscOps.addUniform(alg.derivX, rand, 0f, 0.1f);
    GImageMiscOps.addUniform(alg.derivY, rand, 0f, 0.1f);
    // generate some synthetic data.  This will be composed of random points in front of the camera
    for (int i = 0; i < 100; i++) {
        VisOdomDirectColorDepth.Pixel p = alg.keypixels.grow();
        for (int band = 0; band < numBands; band++) {
            p.bands[band] = colorBefore;
        }
        p.x = rand.nextInt(width);
        p.y = rand.nextInt(height);
        float nx = (p.x - cx) / fx;
        float ny = (p.y - cy) / fy;
        // z needs to fixed value for it to generate a purely translational motion given fixed  gradient and
        // and fixed delta in color
        float z = 2;
        p.p3.x = nx * z;
        p.p3.y = ny * z;
        p.p3.z = z;
    }
    // estimate the motion
    alg.constructLinearSystem(input, new Se3_F32());
    assertTrue(alg.solveSystem());
    assertEquals(Math.abs(colorAfter - colorBefore), alg.getErrorOptical(), 1e-4f);
    // counting error can cause a drop
    assertTrue(alg.getInboundsPixels() > 95);
    return alg.motionTwist;
}
Also used : GrayF32(boofcv.struct.image.GrayF32) Planar(boofcv.struct.image.Planar) Se3_F32(georegression.struct.se.Se3_F32)

Example 70 with Planar

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

the class ExampleRemovePerspectiveDistortion method main.

public static void main(String[] args) {
    // load a color image
    BufferedImage buffered = UtilImageIO.loadImage(UtilIO.pathExample("goals_and_stuff.jpg"));
    Planar<GrayF32> input = ConvertBufferedImage.convertFromPlanar(buffered, null, true, GrayF32.class);
    RemovePerspectiveDistortion<Planar<GrayF32>> removePerspective = new RemovePerspectiveDistortion<>(400, 500, ImageType.pl(3, GrayF32.class));
    // Order matters! top-left, top-right, bottom-right, bottom-left
    if (!removePerspective.apply(input, new Point2D_F64(267, 182), new Point2D_F64(542, 68), new Point2D_F64(519, 736), new Point2D_F64(276, 570))) {
        throw new RuntimeException("Failed!?!?");
    }
    Planar<GrayF32> output = removePerspective.getOutput();
    BufferedImage flat = ConvertBufferedImage.convertTo_F32(output, null, true);
    ShowImages.showWindow(buffered, "Original Image", true);
    ShowImages.showWindow(flat, "Without Perspective Distortion", true);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) RemovePerspectiveDistortion(boofcv.alg.distort.RemovePerspectiveDistortion) Point2D_F64(georegression.struct.point.Point2D_F64) Planar(boofcv.struct.image.Planar) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Aggregations

Planar (boofcv.struct.image.Planar)73 Test (org.junit.Test)39 GrayF32 (boofcv.struct.image.GrayF32)34 GrayU8 (boofcv.struct.image.GrayU8)28 BufferedImage (java.awt.image.BufferedImage)21 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)20 RectangleLength2D_I32 (georegression.struct.shapes.RectangleLength2D_I32)12 File (java.io.File)9 Bitmap (android.graphics.Bitmap)4 ListDisplayPanel (boofcv.gui.ListDisplayPanel)4 ImageGray (boofcv.struct.image.ImageGray)4 ConfigGeneralDetector (boofcv.abst.feature.detect.interest.ConfigGeneralDetector)3 LensDistortionUniversalOmni (boofcv.alg.distort.universal.LensDistortionUniversalOmni)3 MediaManager (boofcv.io.MediaManager)3 DefaultMediaManager (boofcv.io.wrapper.DefaultMediaManager)3 CameraPinhole (boofcv.struct.calib.CameraPinhole)3 GrayU16 (boofcv.struct.image.GrayU16)3 Homography2D_F64 (georegression.struct.homography.Homography2D_F64)3 Se3_F64 (georegression.struct.se.Se3_F64)3 DescribeRegionPoint (boofcv.abst.feature.describe.DescribeRegionPoint)2