Search in sources :

Example 46 with CameraPinholeBrown

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

the class ExampleCalibrateMonocular method main.

public static void main(String[] args) {
    DetectSingleFiducialCalibration detector;
    List<String> images;
    // Regular Circle Example
    // detector = FactoryFiducialCalibration.circleRegularGrid(null, new ConfigGridDimen(/*numRows*/ 8, /*numCols*/ 10, 1.5, 2.5));
    // images = UtilIO.listByPrefix(UtilIO.pathExample("calibration/mono/Sony_DSC-HX5V_CircleRegular"),"image", null);
    // Hexagonal Circle Example
    // detector = FactoryFiducialCalibration.circleHexagonalGrid(null, new ConfigGridDimen(/*numRows*/ 24, /*numCols*/ 28, 1, 1.2));
    // images = UtilIO.listByPrefix(UtilIO.pathExample("calibration/mono/Sony_DSC-HX5V_CircleHexagonal"),"image", null);
    // Square Grid example
    // detector = FactoryFiducialCalibration.squareGrid(null, new ConfigGridDimen(/*numRows*/ 4, /*numCols*/ 3, 30, 30));
    // images = UtilIO.listByPrefix(UtilIO.pathExample("calibration/stereo/Bumblebee2_Square"),"left", null);
    // ECoCheck Example
    // detector = new MultiToSingleFiducialCalibration(FactoryFiducialCalibration.
    // ecocheck(null, ConfigECoCheckMarkers.
    // singleShape(/*numRows*/ 9, /*numCols*/ 7, /*num markers*/ 1, /* square size */ 30)));
    // images = UtilIO.listByPrefix(UtilIO.pathExample("calibration/stereo/Zed_ecocheck"), "left", null);
    // Chessboard Example
    detector = FactoryFiducialCalibration.chessboardX(null, new ConfigGridDimen(/*numRows*/
    7, /*numCols*/
    5, /*shapeSize*/
    30));
    images = UtilIO.listByPrefix(UtilIO.pathExample("calibration/stereo/Bumblebee2_Chess"), "left", null);
    // Declare and setup the calibration algorithm
    CalibrateMonoPlanar calibrationAlg = new CalibrateMonoPlanar(detector.getLayout());
    // tell it type type of target and which intrinsic parameters to estimate
    calibrationAlg.configurePinhole(/*assumeZeroSkew*/
    true, /*numRadialParam*/
    2, /*includeTangential*/
    false);
    for (String n : images) {
        BufferedImage input = UtilImageIO.loadImageNotNull(n);
        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
    CameraPinholeBrown intrinsic = calibrationAlg.process();
    // save results to a file and print out
    CalibrationIO.save(intrinsic, "intrinsic.yaml");
    calibrationAlg.printStatistics(System.out);
    System.out.println();
    System.out.println("--- Intrinsic Parameters ---");
    System.out.println();
    intrinsic.print();
}
Also used : ConfigGridDimen(boofcv.abst.fiducial.calib.ConfigGridDimen) DetectSingleFiducialCalibration(boofcv.abst.geo.calibration.DetectSingleFiducialCalibration) GrayF32(boofcv.struct.image.GrayF32) CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) CalibrateMonoPlanar(boofcv.abst.geo.calibration.CalibrateMonoPlanar) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 47 with CameraPinholeBrown

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

the class UtilOpenCV method loadPinholeRadial.

/**
 * Loads a pinhole camera model with radian and tangential distortion in OpenCV format
 *
 * @param fileName path to file
 * @return CameraPinholeRadial
 */
public static CameraPinholeBrown loadPinholeRadial(String fileName) {
    FileStorage fs = new FileStorage(new File(fileName).getAbsolutePath(), FileStorage.READ);
    IntPointer width = new IntPointer(1);
    IntPointer height = new IntPointer(1);
    read(fs.get("image_width"), width, -1);
    read(fs.get("image_height"), height, -1);
    Mat K = new Mat();
    read(fs.get("camera_matrix"), K);
    Mat distortion = new Mat();
    read(fs.get("distortion_coefficients"), distortion);
    CameraPinholeBrown boof = new CameraPinholeBrown();
    boof.width = width.get();
    boof.height = height.get();
    DoubleRawIndexer indexerK = K.createIndexer();
    boof.fx = indexerK.get(0, 0);
    boof.skew = indexerK.get(0, 1);
    boof.fy = indexerK.get(1, 1);
    boof.cx = indexerK.get(0, 2);
    boof.cy = indexerK.get(1, 2);
    DoubleRawIndexer indexerD = distortion.createIndexer();
    if (distortion.rows() >= 5)
        boof.setRadial(indexerD.get(0, 0), indexerD.get(1, 0), indexerD.get(4, 0));
    else if (distortion.rows() >= 2)
        boof.setRadial(indexerD.get(0, 0), indexerD.get(1, 0));
    if (distortion.rows() >= 5)
        boof.fsetTangental(indexerD.get(2, 0), indexerD.get(3, 0));
    return boof;
}
Also used : CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) IntPointer(org.bytedeco.javacpp.IntPointer) DoubleRawIndexer(org.bytedeco.javacpp.indexer.DoubleRawIndexer) File(java.io.File)

Example 48 with CameraPinholeBrown

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

the class TestUtilOpenCV method savePinholeRadial.

@Test
void savePinholeRadial() {
    CameraPinholeBrown model = new CameraPinholeBrown();
    model.fsetK(1, 2, 3, 4, 0.65, 100, 7);
    model.fsetRadial(.1, .2, .3);
    model.fsetTangental(0.5, 0.7);
    UtilOpenCV.save(model, "temp.yml");
    CameraPinholeBrown found = UtilOpenCV.loadPinholeRadial("temp.yml");
    assertEquals(model.width, found.width);
    assertEquals(model.height, found.height);
    assertEquals(model.fx, found.fx, 1e-8);
    assertEquals(model.fy, found.fy, 1e-8);
    assertEquals(model.skew, found.skew, 1e-8);
    assertEquals(model.cx, found.cx, 1e-8);
    assertEquals(model.cy, found.cy, 1e-8);
    for (int i = 0; i < 3; i++) {
        assertEquals(model.radial[i], found.radial[i], 1e-8);
    }
    assertEquals(model.t1, found.t1, 1e-8);
    assertEquals(model.t2, found.t2, 1e-8);
    assertTrue(new File("temp.yml").delete());
}
Also used : CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 49 with CameraPinholeBrown

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

the class TestUtilOpenCV method loadBoofCVGenerated.

/**
 * Load an OpenCV file generated by BoofCV. See if BoofCV is really
 * correctly implemented.
 */
@Test
void loadBoofCVGenerated() {
    CameraPinholeBrown expected = new CameraPinholeBrown();
    expected.fsetK(1, 2, 3, 4, 0.65, 100, 7);
    expected.fsetRadial(.1, .2, .3);
    expected.fsetTangental(0.5, 0.7);
    UtilOpenCV.save(expected, "temp.yml");
    CalibrationIO.saveOpencv(expected, "temp.yml");
    CameraPinholeBrown found = UtilOpenCV.loadPinholeRadial("temp.yml");
    assertEquals(expected.width, found.width);
    assertEquals(expected.height, found.height);
    assertEquals(expected.fx, found.fx, 1e-8);
    assertEquals(expected.fy, found.fy, 1e-8);
    assertEquals(expected.skew, found.skew, 1e-8);
    assertEquals(expected.cx, found.cx, 1e-8);
    assertEquals(expected.cy, found.cy, 1e-8);
    for (int i = 0; i < 3; i++) {
        assertEquals(expected.radial[i], found.radial[i], 1e-8);
    }
    assertEquals(expected.t1, found.t1, 1e-8);
    assertEquals(expected.t2, found.t2, 1e-8);
    assertTrue(new File("temp.yml").delete());
}
Also used : CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 50 with CameraPinholeBrown

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

the class TestUtilOpenCV method loadPinholeRadial.

@Test
void loadPinholeRadial() {
    URL url = TestUtilOpenCV.class.getResource("pinhole_distorted.yml");
    CameraPinholeBrown model = UtilOpenCV.loadPinholeRadial(url.getFile());
    assertEquals(640, model.width);
    assertEquals(480, model.height);
    assertEquals(5.2626362816407709e+02, model.fx, 1e-8);
    assertEquals(0, model.skew, 1e-8);
    assertEquals(5.2830704330313858e+02, model.fy, 1e-8);
    assertEquals(3.1306715867053975e+02, model.cx, 1e-8);
    assertEquals(2.4747722332735930e+02, model.cy, 1e-8);
    assertEquals(3, model.radial.length);
    assertEquals(-3.7077854691489726e-01, model.radial[0], 1e-8);
    assertEquals(2.4308561956661329e-01, model.radial[1], 1e-8);
    assertEquals(-1.2351969388838037e-01, model.radial[2], 1e-8);
    assertEquals(4.4148972909019294e-04, model.t1, 1e-8);
    assertEquals(-6.0304229617877381e-04, model.t2, 1e-8);
}
Also used : CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) URL(java.net.URL) Test(org.junit.jupiter.api.Test)

Aggregations

CameraPinholeBrown (boofcv.struct.calib.CameraPinholeBrown)99 Test (org.junit.jupiter.api.Test)62 Se3_F64 (georegression.struct.se.Se3_F64)39 GrayF32 (boofcv.struct.image.GrayF32)29 Point2D_F64 (georegression.struct.point.Point2D_F64)19 SimulatePlanarWorld (boofcv.simulation.SimulatePlanarWorld)16 LensDistortionBrown (boofcv.alg.distort.brown.LensDistortionBrown)14 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)14 BufferedImage (java.awt.image.BufferedImage)14 ArrayList (java.util.ArrayList)12 CameraPinhole (boofcv.struct.calib.CameraPinhole)11 Point2Transform2_F64 (boofcv.struct.distort.Point2Transform2_F64)10 DMatrixRMaj (org.ejml.data.DMatrixRMaj)10 File (java.io.File)9 StereoParameters (boofcv.struct.calib.StereoParameters)6 GrayU8 (boofcv.struct.image.GrayU8)6 Point3D_F64 (georegression.struct.point.Point3D_F64)6 ImageBase (boofcv.struct.image.ImageBase)5 ImageType (boofcv.struct.image.ImageType)5 DogArray (org.ddogleg.struct.DogArray)5