Search in sources :

Example 36 with Planar

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

the class ExampleFisheyeToPinhole method main.

public static void main(String[] args) {
    // Path to image data and calibration data
    String fisheyePath = UtilIO.pathExample("fisheye/theta/");
    // load the fisheye camera parameters
    CameraUniversalOmni fisheyeModel = CalibrationIO.load(new File(fisheyePath, "front.yaml"));
    // Specify what the pinhole camera should look like
    CameraPinhole pinholeModel = new CameraPinhole(400, 400, 0, 300, 300, 600, 600);
    // Create the transform from pinhole to fisheye views
    LensDistortionNarrowFOV pinholeDistort = new LensDistortionPinhole(pinholeModel);
    LensDistortionWideFOV fisheyeDistort = new LensDistortionUniversalOmni(fisheyeModel);
    NarrowToWidePtoP_F32 transform = new NarrowToWidePtoP_F32(pinholeDistort, fisheyeDistort);
    // Load fisheye RGB image
    BufferedImage bufferedFisheye = UtilImageIO.loadImage(fisheyePath, "front_table.jpg");
    Planar<GrayU8> fisheyeImage = ConvertBufferedImage.convertFrom(bufferedFisheye, true, ImageType.pl(3, GrayU8.class));
    // Create the image distorter which will render the image
    InterpolatePixel<Planar<GrayU8>> interp = FactoryInterpolation.createPixel(0, 255, InterpolationType.BILINEAR, BorderType.ZERO, fisheyeImage.getImageType());
    ImageDistort<Planar<GrayU8>, Planar<GrayU8>> distorter = FactoryDistort.distort(false, interp, fisheyeImage.getImageType());
    // Pass in the transform created above
    distorter.setModel(new PointToPixelTransform_F32(transform));
    // Render the image.  The camera will have a rotation of 0 and will thus be looking straight forward
    Planar<GrayU8> pinholeImage = fisheyeImage.createNew(pinholeModel.width, pinholeModel.height);
    distorter.apply(fisheyeImage, pinholeImage);
    BufferedImage bufferedPinhole0 = ConvertBufferedImage.convertTo(pinholeImage, null, true);
    // rotate the virtual pinhole camera to the right
    transform.setRotationWideToNarrow(ConvertRotation3D_F32.eulerToMatrix(EulerType.YXZ, 0.8f, 0, 0, null));
    distorter.apply(fisheyeImage, pinholeImage);
    BufferedImage bufferedPinhole1 = ConvertBufferedImage.convertTo(pinholeImage, null, true);
    // Display the results
    ListDisplayPanel panel = new ListDisplayPanel();
    panel.addImage(bufferedPinhole0, "Pinehole Forward");
    panel.addImage(bufferedPinhole1, "Pinehole Right");
    panel.addImage(bufferedFisheye, "Fisheye");
    panel.setPreferredSize(new Dimension(600, 450));
    ShowImages.showWindow(panel, "Fisheye to Pinhole", true);
}
Also used : LensDistortionPinhole(boofcv.alg.distort.pinhole.LensDistortionPinhole) ListDisplayPanel(boofcv.gui.ListDisplayPanel) CameraPinhole(boofcv.struct.calib.CameraPinhole) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) CameraUniversalOmni(boofcv.struct.calib.CameraUniversalOmni) Planar(boofcv.struct.image.Planar) GrayU8(boofcv.struct.image.GrayU8) LensDistortionUniversalOmni(boofcv.alg.distort.universal.LensDistortionUniversalOmni) File(java.io.File)

Example 37 with Planar

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

the class ExampleRemoveLensDistortion method displayResults.

/**
 * Displays results in a window for easy comparison..
 */
private static void displayResults(BufferedImage orig, Planar<GrayF32> distortedImg, ImageDistort allInside, ImageDistort fullView) {
    // render the results
    Planar<GrayF32> undistortedImg = new Planar<>(GrayF32.class, distortedImg.getWidth(), distortedImg.getHeight(), distortedImg.getNumBands());
    allInside.apply(distortedImg, undistortedImg);
    BufferedImage out1 = ConvertBufferedImage.convertTo(undistortedImg, null, true);
    fullView.apply(distortedImg, undistortedImg);
    BufferedImage out2 = ConvertBufferedImage.convertTo(undistortedImg, null, true);
    // display in a single window where the user can easily switch between images
    ListDisplayPanel panel = new ListDisplayPanel();
    panel.addItem(new ImagePanel(orig), "Original");
    panel.addItem(new ImagePanel(out1), "Undistorted All Inside");
    panel.addItem(new ImagePanel(out2), "Undistorted Full View");
    ShowImages.showWindow(panel, "Removing Lens Distortion", true);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) ListDisplayPanel(boofcv.gui.ListDisplayPanel) Planar(boofcv.struct.image.Planar) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) ImagePanel(boofcv.gui.image.ImagePanel)

Example 38 with Planar

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

the class TestSegmentMeanShiftSearchColor method simpleTest.

/**
 * Process a random image and do a basic sanity check on the output
 */
@Test
public void simpleTest() {
    Planar<GrayF32> image = new Planar<>(GrayF32.class, 20, 25, 2);
    GImageMiscOps.fillUniform(image, rand, 0, 256);
    SegmentMeanShiftSearchColor<Planar<GrayF32>> alg = new SegmentMeanShiftSearchColor<>(30, 0.05f, interp, 2, 2, 200, false, imageType);
    alg.process(image);
    FastQueue<Point2D_I32> locations = alg.getModeLocation();
    GrowQueue_I32 counts = alg.getRegionMemberCount();
    GrayS32 peaks = alg.getPixelToRegion();
    FastQueue<float[]> values = alg.getModeColor();
    // there should be a fair number of local peaks due to the image being random
    assertTrue(locations.size > 20);
    // all the lists should be the same size
    assertEquals(locations.size, counts.size);
    assertEquals(locations.size, values.size);
    // total members should equal the number of pixels
    int totalMembers = 0;
    for (int i = 0; i < counts.size; i++) {
        totalMembers += counts.get(i);
    }
    assertEquals(20 * 25, totalMembers);
    // see if the peak to index image is set up correctly and that all the peaks make sense
    for (int y = 0; y < peaks.height; y++) {
        for (int x = 0; x < peaks.width; x++) {
            int peak = peaks.get(x, y);
            // can't test the value because its floating point location which is interpolated using the kernel
            // and the location is lost
            // assertEquals(x+" "+y,computeValue(peakX,peakY,image),value,50);
            assertTrue(counts.get(peak) > 0);
        }
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) Planar(boofcv.struct.image.Planar) Point2D_I32(georegression.struct.point.Point2D_I32) GrayS32(boofcv.struct.image.GrayS32) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32) Test(org.junit.Test)

Example 39 with Planar

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

the class TestVisualDepthOps method depthTo3D_with_rgb.

@Test
public void depthTo3D_with_rgb() {
    GrayU16 depth = new GrayU16(width, height);
    depth.set(200, 80, 3400);
    depth.set(600, 420, 50);
    Planar<GrayU8> rgb = new Planar<>(GrayU8.class, width, height, 3);
    GImageMiscOps.fillUniform(rgb, rand, 0, 200);
    FastQueue<Point3D_F64> pts = new FastQueue<>(Point3D_F64.class, true);
    FastQueueArray_I32 color = new FastQueueArray_I32(3);
    VisualDepthOps.depthTo3D(param, rgb, depth, pts, color);
    assertEquals(2, pts.size());
    assertEquals(2, color.size());
    assertEquals(0, compute(200, 80, 3400).distance(pts.get(0)), 1e-8);
    assertEquals(0, compute(600, 420, 50).distance(pts.get(1)), 1e-8);
    color(200, 80, rgb, color.get(0));
    color(600, 420, rgb, color.get(1));
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) GrayU16(boofcv.struct.image.GrayU16) FastQueue(org.ddogleg.struct.FastQueue) Planar(boofcv.struct.image.Planar) GrayU8(boofcv.struct.image.GrayU8) FastQueueArray_I32(boofcv.struct.FastQueueArray_I32) Test(org.junit.Test)

Example 40 with Planar

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

the class TestCreateSyntheticOverheadViewPL method checkRender.

@Test
public void checkRender() {
    // 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);
    CreateSyntheticOverheadViewPL<GrayF32> alg = new CreateSyntheticOverheadViewPL<>(InterpolationType.BILINEAR, 3, GrayF32.class);
    alg.configure(param, planeToCamera, centerX, centerY, cellSize, overheadW, overheadH);
    Planar<GrayF32> input = new Planar<>(GrayF32.class, width, height, 3);
    for (int i = 0; i < 3; i++) ImageMiscOps.fill(input.getBand(i), 10 + i);
    Planar<GrayF32> output = new Planar<>(GrayF32.class, overheadW, overheadH, 3);
    alg.process(input, output);
    for (int i = 0; i < 3; i++) {
        GrayF32 o = output.getBand(i);
        // check parts that shouldn't be in view
        assertEquals(0, o.get(0, 300), 1e-8);
        assertEquals(0, o.get(5, 0), 1e-8);
        assertEquals(0, o.get(5, 599), 1e-8);
        // check areas that should be in view
        assertEquals(10 + i, o.get(499, 300), 1e-8);
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) Planar(boofcv.struct.image.Planar) Se3_F64(georegression.struct.se.Se3_F64) 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