Search in sources :

Example 71 with Planar

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

the class ExampleEquirectangularToPinhole method main.

public static void main(String[] args) {
    // Specify what the pinhole camera should look like
    CameraPinhole pinholeModel = new CameraPinhole(200, 200, 0, 250, 250, 500, 500);
    // Load equirectangular RGB image
    BufferedImage bufferedEqui = UtilImageIO.loadImage(UtilIO.pathExample("spherical/equirectangular_half_dome_01.jpg"));
    Planar<GrayU8> equiImage = ConvertBufferedImage.convertFrom(bufferedEqui, true, ImageType.pl(3, GrayU8.class));
    // Declare storage for pinhole camera image
    Planar<GrayU8> pinholeImage = equiImage.createNew(pinholeModel.width, pinholeModel.height);
    // Create the image distorter which will render the image
    InterpolatePixel<Planar<GrayU8>> interp = FactoryInterpolation.createPixel(0, 255, InterpolationType.BILINEAR, BorderType.EXTENDED, equiImage.getImageType());
    ImageDistort<Planar<GrayU8>, Planar<GrayU8>> distorter = FactoryDistort.distort(false, interp, equiImage.getImageType());
    // This is where the magic is done.  It defines the transform rfom equirectangular to pinhole
    PinholeToEquirectangular_F32 pinholeToEqui = new PinholeToEquirectangular_F32();
    pinholeToEqui.setEquirectangularShape(equiImage.width, equiImage.height);
    pinholeToEqui.setPinhole(pinholeModel);
    // Pass in the transform to the image distorter
    distorter.setModel(pinholeToEqui);
    // change the orientation of the camera to make the view better
    ConvertRotation3D_F32.eulerToMatrix(EulerType.YXZ, 0, 1.45f, 2.2f, pinholeToEqui.getRotation());
    // Render the image
    distorter.apply(equiImage, pinholeImage);
    BufferedImage bufferedPinhole0 = ConvertBufferedImage.convertTo(pinholeImage, null, true);
    // Let's look at another view
    ConvertRotation3D_F32.eulerToMatrix(EulerType.YXZ, 0, 1.25f, -1.25f, pinholeToEqui.getRotation());
    distorter.apply(equiImage, pinholeImage);
    BufferedImage bufferedPinhole1 = ConvertBufferedImage.convertTo(pinholeImage, null, true);
    // Display the results
    ListDisplayPanel panel = new ListDisplayPanel();
    panel.addImage(bufferedPinhole0, "Pinehole View 0");
    panel.addImage(bufferedPinhole1, "Pinehole View 1");
    panel.addImage(bufferedEqui, "Equirectangular");
    panel.setPreferredSize(new Dimension(equiImage.width, equiImage.height));
    ShowImages.showWindow(panel, "Equirectangular to Pinhole", true);
}
Also used : PinholeToEquirectangular_F32(boofcv.alg.distort.spherical.PinholeToEquirectangular_F32) ListDisplayPanel(boofcv.gui.ListDisplayPanel) Planar(boofcv.struct.image.Planar) GrayU8(boofcv.struct.image.GrayU8) CameraPinhole(boofcv.struct.calib.CameraPinhole) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 72 with Planar

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

the class DisplayFisheyeCalibrationPanel method setCalibration.

public void setCalibration(CameraUniversalOmni fisheyeModel) {
    BoofSwingUtil.checkGuiThread();
    LensDistortionNarrowFOV pinholeDistort = new LensDistortionPinhole(pinholeModel);
    fisheyeDistort = new LensDistortionUniversalOmni(fisheyeModel);
    distorter = new NarrowToWidePtoP_F32(pinholeDistort, fisheyeDistort);
    // Create the image distorter which will render the image
    InterpolatePixel<Planar<GrayF32>> interp = FactoryInterpolation.createPixel(0, 255, InterpolationType.BILINEAR, BorderType.ZERO, imageFisheye.getImageType());
    distortImage = FactoryDistort.distort(false, interp, imageFisheye.getImageType());
    // Pass in the transform created above
    distortImage.setModel(new PointToPixelTransform_F32(distorter));
    setPinholeCenter(fisheyeModel.width / 2, fisheyeModel.height / 2);
    renderPinhole();
}
Also used : LensDistortionPinhole(boofcv.alg.distort.pinhole.LensDistortionPinhole) Planar(boofcv.struct.image.Planar) LensDistortionUniversalOmni(boofcv.alg.distort.universal.LensDistortionUniversalOmni)

Example 73 with Planar

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

the class TestDataManipulationOps method imageToTensor.

@Test
public void imageToTensor() {
    Planar<GrayF32> image = new Planar<>(GrayF32.class, 30, 25, 2);
    GImageMiscOps.fillUniform(image, rand, -2, 2);
    Tensor_F32 tensor = new Tensor_F32(1, 2, 25, 30);
    DataManipulationOps.imageToTensor(image, tensor, 0);
    for (int band = 0; band < image.bands.length; band++) {
        for (int i = 0; i < image.height; i++) {
            for (int j = 0; j < image.width; j++) {
                assertEquals(image.getBand(band).get(j, i), tensor.get(0, band, i, j), 1e-4f);
            }
        }
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) Planar(boofcv.struct.image.Planar) Tensor_F32(deepboof.tensors.Tensor_F32) 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