Search in sources :

Example 1 with MultiCameraToEquirectangular

use of boofcv.alg.distort.spherical.MultiCameraToEquirectangular in project BoofCV by lessthanoptimal.

the class ExampleFisheyeToEquirectangular 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 model0 = CalibrationIO.load(new File(fisheyePath, "front.yaml"));
    CameraUniversalOmni model1 = CalibrationIO.load(new File(fisheyePath, "back.yaml"));
    LensDistortionWideFOV distort0 = new LensDistortionUniversalOmni(model0);
    LensDistortionWideFOV distort1 = new LensDistortionUniversalOmni(model1);
    ImageType<Planar<GrayF32>> imageType = ImageType.pl(3, GrayF32.class);
    InterpolatePixel<Planar<GrayF32>> interp = FactoryInterpolation.createPixel(0, 255, InterpolationType.BILINEAR, BorderType.ZERO, imageType);
    ImageDistort<Planar<GrayF32>, Planar<GrayF32>> distort = FactoryDistort.distort(false, interp, imageType);
    // This will create an equirectangular image with 800 x 400 pixels
    MultiCameraToEquirectangular<Planar<GrayF32>> alg = new MultiCameraToEquirectangular<>(distort, 800, 400, imageType);
    // this is an important parameter and is used to filter out falsely mirrored pixels
    alg.setMaskToleranceAngle(UtilAngle.radian(0.1f));
    // camera has a known FOV of 185 degrees
    GrayU8 mask0 = createMask(model0, distort0, UtilAngle.radian(182));
    // the edges are likely to be noisy,
    GrayU8 mask1 = createMask(model1, distort1, UtilAngle.radian(182));
    // so crop it a bit..
    // Rotate camera axis so that +x is forward and not +z and make it visually pleasing
    FMatrixRMaj adjR = ConvertRotation3D_F32.eulerToMatrix(EulerType.XYZ, GrlConstants.F_PI / 2, 0, 0, null);
    // Rotation from the front camera to the back facing camera.
    // This is only an approximation.  Should be determined through calibration.
    FMatrixRMaj f2b = ConvertRotation3D_F32.eulerToMatrix(EulerType.ZYX, GrlConstants.F_PI, 0, 0, null);
    Se3_F32 frontToFront = new Se3_F32();
    frontToFront.setRotation(adjR);
    Se3_F32 frontToBack = new Se3_F32();
    CommonOps_FDRM.mult(f2b, adjR, frontToBack.R);
    // add the camera and specify which pixels are valid.  These functions precompute the entire transform
    // and can be relatively slow, but generating the equirectangular image should be much faster
    alg.addCamera(frontToBack, distort0, mask0);
    alg.addCamera(frontToFront, distort1, mask1);
    // Load fisheye RGB image
    BufferedImage buffered0 = UtilImageIO.loadImage(fisheyePath, "front_table.jpg");
    Planar<GrayF32> fisheye0 = ConvertBufferedImage.convertFrom(buffered0, true, ImageType.pl(3, GrayF32.class));
    BufferedImage buffered1 = UtilImageIO.loadImage(fisheyePath, "back_table.jpg");
    Planar<GrayF32> fisheye1 = ConvertBufferedImage.convertFrom(buffered1, true, ImageType.pl(3, GrayF32.class));
    List<Planar<GrayF32>> images = new ArrayList<>();
    images.add(fisheye0);
    images.add(fisheye1);
    alg.render(images);
    BufferedImage equiOut = ConvertBufferedImage.convertTo(alg.getRenderedImage(), null, true);
    ShowImages.showWindow(equiOut, "Dual Fisheye to Equirectangular", true);
}
Also used : FMatrixRMaj(org.ejml.data.FMatrixRMaj) LensDistortionWideFOV(boofcv.alg.distort.LensDistortionWideFOV) ArrayList(java.util.ArrayList) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) GrayF32(boofcv.struct.image.GrayF32) MultiCameraToEquirectangular(boofcv.alg.distort.spherical.MultiCameraToEquirectangular) 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) Se3_F32(georegression.struct.se.Se3_F32)

Aggregations

LensDistortionWideFOV (boofcv.alg.distort.LensDistortionWideFOV)1 MultiCameraToEquirectangular (boofcv.alg.distort.spherical.MultiCameraToEquirectangular)1 LensDistortionUniversalOmni (boofcv.alg.distort.universal.LensDistortionUniversalOmni)1 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)1 CameraUniversalOmni (boofcv.struct.calib.CameraUniversalOmni)1 GrayF32 (boofcv.struct.image.GrayF32)1 GrayU8 (boofcv.struct.image.GrayU8)1 Planar (boofcv.struct.image.Planar)1 Se3_F32 (georegression.struct.se.Se3_F32)1 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 FMatrixRMaj (org.ejml.data.FMatrixRMaj)1