Search in sources :

Example 6 with CameraUniversalOmni

use of boofcv.struct.calib.CameraUniversalOmni in project BoofCV by lessthanoptimal.

the class TestUniOmniStoP_F64 method worldIsImageCenter.

/**
 * A point in the world center should appear in the image center
 */
@Test
public void worldIsImageCenter() {
    CameraUniversalOmni model = createModel(0.5);
    UniOmniStoP_F64 alg = new UniOmniStoP_F64();
    alg.setModel(model);
    Point2D_F64 found = new Point2D_F64(10, 10);
    // directly forward on unit sphere
    alg.compute(0, 0, 1, found);
    assertEquals(320, found.x, GrlConstants.TEST_F64);
    assertEquals(240, found.y, GrlConstants.TEST_F64);
}
Also used : CameraUniversalOmni(boofcv.struct.calib.CameraUniversalOmni) Point2D_F64(georegression.struct.point.Point2D_F64) Test(org.junit.Test)

Example 7 with CameraUniversalOmni

use of boofcv.struct.calib.CameraUniversalOmni in project BoofCV by lessthanoptimal.

the class FisheyePinholeApp method openFile.

@Override
public void openFile(File file) {
    File intrinsicFile = new File(file.getParent(), "front.yaml");
    CameraUniversalOmni fisheyeModel = CalibrationIO.load(intrinsicFile);
    fisheyeDistort = new LensDistortionUniversalOmni(fisheyeModel);
    distorter.configure(new LensDistortionPinhole(cameraModel), fisheyeDistort);
    super.openFile(file);
}
Also used : LensDistortionPinhole(boofcv.alg.distort.pinhole.LensDistortionPinhole) CameraUniversalOmni(boofcv.struct.calib.CameraUniversalOmni) LensDistortionUniversalOmni(boofcv.alg.distort.universal.LensDistortionUniversalOmni) File(java.io.File)

Example 8 with CameraUniversalOmni

use of boofcv.struct.calib.CameraUniversalOmni in project BoofCV by lessthanoptimal.

the class ExampleCalibrateFisheye method main.

public static void main(String[] args) {
    DetectorFiducialCalibration detector;
    List<String> images;
    // Circle based calibration targets not not recommended because the sever lens distortion will change
    // the apparent location of tangent points.
    // Square Grid example
    // detector = FactoryFiducialCalibration.squareGrid(new ConfigSquareGrid(4, 3, 30, 30));
    // images = UtilIO.listAll(UtilIO.pathExample("calibration/fisheye/square_grid"));
    // Chessboard Example
    detector = FactoryFiducialCalibration.chessboard(new ConfigChessboard(7, 5, 30));
    images = UtilIO.listAll(UtilIO.pathExample("calibration/fisheye/chessboard"));
    // Declare and setup the calibration algorithm
    CalibrateMonoPlanar calibrationAlg = new CalibrateMonoPlanar(detector.getLayout());
    // tell it type type of target and which parameters to estimate
    calibrationAlg.configureUniversalOmni(true, 2, false);
    for (String n : images) {
        BufferedImage input = UtilImageIO.loadImage(n);
        if (input != null) {
            GrayF32 image = ConvertBufferedImage.convertFrom(input, (GrayF32) null);
            if (detector.process(image)) {
                calibrationAlg.addImage(detector.getDetectedPoints().copy());
            } else {
                System.err.println("Failed to detect target in " + n);
            }
        }
    }
    // process and compute intrinsic parameters
    CameraUniversalOmni intrinsic = calibrationAlg.process();
    // save results to a file and print out
    CalibrationIO.save(intrinsic, "fisheye.yaml");
    calibrationAlg.printStatistics();
    System.out.println();
    System.out.println("--- Intrinsic Parameters ---");
    System.out.println();
    intrinsic.print();
}
Also used : DetectorFiducialCalibration(boofcv.abst.geo.calibration.DetectorFiducialCalibration) GrayF32(boofcv.struct.image.GrayF32) CameraUniversalOmni(boofcv.struct.calib.CameraUniversalOmni) ConfigChessboard(boofcv.abst.fiducial.calib.ConfigChessboard) CalibrateMonoPlanar(boofcv.abst.geo.calibration.CalibrateMonoPlanar) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 9 with CameraUniversalOmni

use of boofcv.struct.calib.CameraUniversalOmni 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)

Example 10 with CameraUniversalOmni

use of boofcv.struct.calib.CameraUniversalOmni 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)

Aggregations

CameraUniversalOmni (boofcv.struct.calib.CameraUniversalOmni)19 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)6 GrayF32 (boofcv.struct.image.GrayF32)6 BufferedImage (java.awt.image.BufferedImage)6 File (java.io.File)6 LensDistortionUniversalOmni (boofcv.alg.distort.universal.LensDistortionUniversalOmni)5 ArrayList (java.util.ArrayList)5 Point2D_F64 (georegression.struct.point.Point2D_F64)3 Test (org.junit.Test)3 CalibrateMonoPlanar (boofcv.abst.geo.calibration.CalibrateMonoPlanar)2 DetectorFiducialCalibration (boofcv.abst.geo.calibration.DetectorFiducialCalibration)2 LensDistortionPinhole (boofcv.alg.distort.pinhole.LensDistortionPinhole)2 GrayU8 (boofcv.struct.image.GrayU8)2 Planar (boofcv.struct.image.Planar)2 Point2D_F32 (georegression.struct.point.Point2D_F32)2 Point3D_F32 (georegression.struct.point.Point3D_F32)2 Point3D_F64 (georegression.struct.point.Point3D_F64)2 Se3_F64 (georegression.struct.se.Se3_F64)2 ConfigChessboard (boofcv.abst.fiducial.calib.ConfigChessboard)1 LensDistortionWideFOV (boofcv.alg.distort.LensDistortionWideFOV)1