Search in sources :

Example 16 with Planar

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

the class TestImplConvertBitmap method checkPlanarToArray.

public void checkPlanarToArray(Method m, Bitmap.Config config) {
    Bitmap dst = Bitmap.createBitmap(w, h, config);
    Class[] params = m.getParameterTypes();
    try {
        int numBands = Bitmap.Config.ARGB_8888 == config ? 4 : 3;
        Class msType = m.getName().contains("U8") ? GrayU8.class : GrayF32.class;
        Planar src = new Planar(msType, w, h, numBands);
        GeneralizedImageOps.set(src.getBand(0), 1, 2, 0x38);
        GeneralizedImageOps.set(src.getBand(1), 1, 2, 0x64);
        GeneralizedImageOps.set(src.getBand(2), 1, 2, 0xFF);
        if (numBands == 4)
            GeneralizedImageOps.set(src.getBand(3), 1, 2, 0xFF);
        Object array;
        String info = params[0].getSimpleName();
        if (params[2] == int[].class) {
            info += " Array32";
            array = buffer32;
        } else {
            info += " Array8";
            array = buffer8;
        }
        info += " " + config;
        m.invoke(null, src, array, config);
        if (params[2] == int[].class) {
            dst.copyPixelsFromBuffer(IntBuffer.wrap(buffer32));
        } else {
            dst.copyPixelsFromBuffer(ByteBuffer.wrap(buffer8));
        }
        if (config == Bitmap.Config.ARGB_8888) {
            assertEquals(info, 0xFF3864FF, (int) dst.getPixel(1, 2));
            assertEquals(info, 0x00000000, dst.getPixel(0, 0));
        } else {
            assertEquals(info, expected565(0x38, 0x64, 0xFF), (int) dst.getPixel(1, 2));
            assertEquals(info, 0xFF000000, dst.getPixel(0, 0));
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Bitmap(android.graphics.Bitmap) Planar(boofcv.struct.image.Planar)

Example 17 with Planar

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

the class TestImplConvertBitmap method checkPlanarToBitmapRGB.

public void checkPlanarToBitmapRGB(Method m, Bitmap.Config config) {
    Bitmap dst = Bitmap.createBitmap(w, h, config);
    Class[] params = m.getParameterTypes();
    try {
        int numBands = Bitmap.Config.ARGB_8888 == config ? 4 : 3;
        Class msType = m.getName().contains("U8") ? GrayU8.class : GrayF32.class;
        Planar src = new Planar(msType, w, h, numBands);
        GeneralizedImageOps.set(src.getBand(0), 1, 2, 0x38);
        GeneralizedImageOps.set(src.getBand(1), 1, 2, 0x64);
        GeneralizedImageOps.set(src.getBand(2), 1, 2, 0xFF);
        if (numBands == 4)
            GeneralizedImageOps.set(src.getBand(3), 1, 2, 0xFF);
        String info = m.getName() + " " + config;
        m.invoke(null, src, dst);
        if (config == Bitmap.Config.ARGB_8888) {
            assertEquals(info, 0xFF3864FF, (int) dst.getPixel(1, 2));
            assertEquals(info, 0x00000000, dst.getPixel(0, 0));
        } else {
            assertEquals(info, expected565(0x38, 0x64, 0xFF), (int) dst.getPixel(1, 2));
            assertEquals(info, 0xFF000000, dst.getPixel(0, 0));
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Bitmap(android.graphics.Bitmap) Planar(boofcv.struct.image.Planar)

Example 18 with Planar

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

the class TestImplConvertBitmap method checkArrayToPlanar.

public void checkArrayToPlanar(Method m, Bitmap.Config config) {
    Bitmap orig = Bitmap.createBitmap(w, h, config);
    orig.setPixel(1, 2, 0xFF204010);
    Class[] params = m.getParameterTypes();
    try {
        int numBands = Bitmap.Config.ARGB_8888 == config ? 4 : 3;
        Class msType = m.getName().contains("U8") ? GrayU8.class : GrayF32.class;
        Planar found = new Planar(msType, w, h, numBands);
        Object array;
        String info = params[2].getSimpleName();
        if (params[0] == int[].class) {
            info += " Array32";
            orig.copyPixelsToBuffer(IntBuffer.wrap(buffer32));
            array = buffer32;
        } else {
            info += " Array8";
            orig.copyPixelsToBuffer(ByteBuffer.wrap(buffer8));
            array = buffer8;
        }
        info += " " + config;
        m.invoke(null, array, config, found);
        assertEquals(0x20, (int) GeneralizedImageOps.get(found.getBand(0), 1, 2));
        assertEquals(0x40, (int) GeneralizedImageOps.get(found.getBand(1), 1, 2));
        assertEquals(0x10, (int) GeneralizedImageOps.get(found.getBand(2), 1, 2));
        if (numBands == 4)
            assertEquals(0xFF, (int) GeneralizedImageOps.get(found.getBand(3), 1, 2));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Bitmap(android.graphics.Bitmap) Planar(boofcv.struct.image.Planar)

Example 19 with Planar

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

the class JCodecSimplified method getGuiImage.

@Override
public <InternalImage> InternalImage getGuiImage() {
    Planar<GrayU8> boofColor = new Planar<>(GrayU8.class, frameCurrent.getWidth(), frameCurrent.getHeight(), 3);
    BufferedImage output = new BufferedImage(boofColor.width, boofColor.height, BufferedImage.TYPE_INT_RGB);
    UtilJCodec.convertToBoof(frameCurrent, boofColor);
    ConvertBufferedImage.convertTo(boofColor, output, true);
    return (InternalImage) output;
}
Also used : Planar(boofcv.struct.image.Planar) GrayU8(boofcv.struct.image.GrayU8) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 20 with Planar

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

the class TestUtilImageIO method loadImage_saveImage_PPM.

@Test
public void loadImage_saveImage_PPM() throws IOException {
    Planar<GrayU8> orig = new Planar<>(GrayU8.class, width, height, 3);
    GImageMiscOps.fillUniform(orig, rand, 0, 256);
    File temp = File.createTempFile("temp", ".png");
    UtilImageIO.savePPM(orig, temp.getPath(), null);
    Planar<GrayU8> found = UtilImageIO.loadPPM_U8(temp.getPath(), null, null);
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            for (int k = 0; k < 3; k++) assertEquals(orig.getBand(k).get(x, y), found.getBand(k).get(x, y));
        }
    }
    // clean up
    // no assertTrue() here because in windows it will fail
    temp.delete();
}
Also used : Planar(boofcv.struct.image.Planar) GrayU8(boofcv.struct.image.GrayU8) File(java.io.File) Test(org.junit.Test)

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