Search in sources :

Example 1 with LensDistortionPinhole

use of boofcv.alg.distort.pinhole.LensDistortionPinhole in project BoofCV by lessthanoptimal.

the class TestNarrowToWidePtoP_F32 method createModelNarrow.

public static LensDistortionNarrowFOV createModelNarrow() {
    CameraPinhole model = new CameraPinhole();
    model.fsetK(400, 400, 0, 250, 250, 500, 500);
    return new LensDistortionPinhole(model);
}
Also used : LensDistortionPinhole(boofcv.alg.distort.pinhole.LensDistortionPinhole) CameraPinhole(boofcv.struct.calib.CameraPinhole)

Example 2 with LensDistortionPinhole

use of boofcv.alg.distort.pinhole.LensDistortionPinhole 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) LensDistortionNarrowFOV(boofcv.alg.distort.LensDistortionNarrowFOV) LensDistortionWideFOV(boofcv.alg.distort.LensDistortionWideFOV) NarrowToWidePtoP_F32(boofcv.alg.distort.NarrowToWidePtoP_F32) CameraPinhole(boofcv.struct.calib.CameraPinhole) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) CameraUniversalOmni(boofcv.struct.calib.CameraUniversalOmni) PointToPixelTransform_F32(boofcv.struct.distort.PointToPixelTransform_F32) Planar(boofcv.struct.image.Planar) GrayU8(boofcv.struct.image.GrayU8) LensDistortionUniversalOmni(boofcv.alg.distort.universal.LensDistortionUniversalOmni) File(java.io.File)

Example 3 with LensDistortionPinhole

use of boofcv.alg.distort.pinhole.LensDistortionPinhole in project BoofCV by lessthanoptimal.

the class TestPerspectiveOps method estimatePinhole.

/**
 * Test using a known pinhole model which fits its assumptions perfectly
 */
@Test
void estimatePinhole() {
    CameraPinhole expected = new CameraPinhole(500, 550, 0, 600, 700, 1200, 1400);
    Point2Transform2_F64 pixelToNorm = new LensDistortionPinhole(expected).distort_F64(true, false);
    CameraPinhole found = PerspectiveOps.estimatePinhole(pixelToNorm, expected.width, expected.height);
    assertEquals(expected.fx, found.fx, UtilEjml.TEST_F64);
    assertEquals(expected.fy, found.fy, UtilEjml.TEST_F64);
    assertEquals(expected.cx, found.cx, UtilEjml.TEST_F64);
    assertEquals(expected.cy, found.cy, UtilEjml.TEST_F64);
    assertEquals(expected.skew, found.skew, UtilEjml.TEST_F64);
    assertEquals(expected.width, found.width);
    assertEquals(expected.height, found.height);
}
Also used : LensDistortionPinhole(boofcv.alg.distort.pinhole.LensDistortionPinhole) Point2Transform2_F64(boofcv.struct.distort.Point2Transform2_F64) CameraPinhole(boofcv.struct.calib.CameraPinhole) Test(org.junit.jupiter.api.Test)

Example 4 with LensDistortionPinhole

use of boofcv.alg.distort.pinhole.LensDistortionPinhole in project BoofCV by lessthanoptimal.

the class TestPerspectiveOps method approximatePinhole.

@Test
void approximatePinhole() {
    CameraPinhole original = PerspectiveOps.createIntrinsic(640, 480, 75, 70, null);
    LensDistortionPinhole distortion = new LensDistortionPinhole(original);
    CameraPinhole found = PerspectiveOps.approximatePinhole(distortion.undistort_F64(true, false), original.width, original.height);
    assertEquals(original.width, found.width);
    assertEquals(original.width, found.width);
    assertEquals(original.skew, found.skew, UtilEjml.TEST_F64);
    assertEquals(original.fx, found.fx, 1);
    assertEquals(original.fy, found.fy, 1);
}
Also used : LensDistortionPinhole(boofcv.alg.distort.pinhole.LensDistortionPinhole) CameraPinhole(boofcv.struct.calib.CameraPinhole) Test(org.junit.jupiter.api.Test)

Example 5 with LensDistortionPinhole

use of boofcv.alg.distort.pinhole.LensDistortionPinhole in project BoofCV by lessthanoptimal.

the class TestNarrowToWidePtoP_F64 method createModelNarrow.

public static LensDistortionNarrowFOV createModelNarrow() {
    CameraPinhole model = new CameraPinhole();
    model.fsetK(400, 400, 0, 250, 250, 500, 500);
    return new LensDistortionPinhole(model);
}
Also used : LensDistortionPinhole(boofcv.alg.distort.pinhole.LensDistortionPinhole) CameraPinhole(boofcv.struct.calib.CameraPinhole)

Aggregations

LensDistortionPinhole (boofcv.alg.distort.pinhole.LensDistortionPinhole)17 CameraPinhole (boofcv.struct.calib.CameraPinhole)7 Test (org.junit.jupiter.api.Test)6 LensDistortionNarrowFOV (boofcv.alg.distort.LensDistortionNarrowFOV)4 Point2Transform2_F64 (boofcv.struct.distort.Point2Transform2_F64)4 GrayU8 (boofcv.struct.image.GrayU8)4 LensDistortionUniversalOmni (boofcv.alg.distort.universal.LensDistortionUniversalOmni)3 PointToPixelTransform_F32 (boofcv.struct.distort.PointToPixelTransform_F32)3 GrayF32 (boofcv.struct.image.GrayF32)3 Planar (boofcv.struct.image.Planar)3 UtilPoint3D_F64 (georegression.geometry.UtilPoint3D_F64)3 Point3D_F64 (georegression.struct.point.Point3D_F64)3 NarrowToWidePtoP_F32 (boofcv.alg.distort.NarrowToWidePtoP_F32)2 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)2 CameraUniversalOmni (boofcv.struct.calib.CameraUniversalOmni)2 Point2D_F64 (georegression.struct.point.Point2D_F64)2 Se3_F64 (georegression.struct.se.Se3_F64)2 BufferedImage (java.awt.image.BufferedImage)2 File (java.io.File)2 LensDistortionWideFOV (boofcv.alg.distort.LensDistortionWideFOV)1