Search in sources :

Example 1 with ConfigGridDimen

use of boofcv.abst.fiducial.calib.ConfigGridDimen in project BoofCV by lessthanoptimal.

the class FiducialDetection method parseChessboard.

void parseChessboard(int index, String[] args) {
    int rows = -1, cols = -1;
    double width = 1;
    for (; index < args.length; index++) {
        String arg = args[index];
        if (!arg.startsWith("--")) {
            throw new RuntimeException("Expected flags for chessboard calibration fiducial");
        }
        splitFlag(arg);
        if (flagName.compareToIgnoreCase("Shape") == 0) {
            String[] words = parameters.split(":");
            if (words.length != 2)
                throw new RuntimeException("Expected two for rows and columns");
            rows = Integer.parseInt(words[0]);
            cols = Integer.parseInt(words[1]);
        } else if (flagName.compareToIgnoreCase("SquareWidth") == 0) {
            width = Double.parseDouble(parameters);
        } else {
            throw new RuntimeException("Unknown chessboard option " + flagName);
        }
    }
    if (rows < 1 || cols < 1)
        throw new RuntimeException("Must specify number of rows and columns");
    System.out.println("chessboard: rows = " + rows + " columns = " + cols + "  square width " + width);
    ConfigGridDimen config = new ConfigGridDimen(rows, cols, width);
    detector = FactoryFiducial.calibChessboardX(null, config, GrayU8.class);
}
Also used : ConfigGridDimen(boofcv.abst.fiducial.calib.ConfigGridDimen) GrayU8(boofcv.struct.image.GrayU8)

Example 2 with ConfigGridDimen

use of boofcv.abst.fiducial.calib.ConfigGridDimen in project BoofCV by lessthanoptimal.

the class FiducialDetection method parseSquareGrid.

void parseSquareGrid(int index, String[] args) {
    int rows = -1, cols = -1;
    double width = 1, space = -1;
    for (; index < args.length; index++) {
        String arg = args[index];
        if (!arg.startsWith("--")) {
            throw new RuntimeException("Expected flags for square grid calibration fiducial");
        }
        splitFlag(arg);
        if (flagName.compareToIgnoreCase("Shape") == 0) {
            String[] words = parameters.split(":");
            if (words.length != 2)
                throw new RuntimeException("Expected two for rows and columns");
            rows = Integer.parseInt(words[0]);
            cols = Integer.parseInt(words[1]);
        } else if (flagName.compareToIgnoreCase("SquareWidth") == 0) {
            width = Double.parseDouble(parameters);
        } else if (flagName.compareToIgnoreCase("Space") == 0) {
            space = Double.parseDouble(parameters);
        } else {
            throw new RuntimeException("Unknown square grid option " + flagName);
        }
    }
    if (rows < 1 || cols < 1)
        throw new RuntimeException("Must specify number of rows and columns");
    if (space <= 0)
        space = width;
    System.out.println("square grid: rows = " + rows + " columns = " + cols + "  square width " + width + "  space " + space);
    ConfigGridDimen config = new ConfigGridDimen(rows, cols, width, space);
    detector = FactoryFiducial.calibSquareGrid(null, config, GrayU8.class);
}
Also used : ConfigGridDimen(boofcv.abst.fiducial.calib.ConfigGridDimen) GrayU8(boofcv.struct.image.GrayU8)

Example 3 with ConfigGridDimen

use of boofcv.abst.fiducial.calib.ConfigGridDimen in project BoofCV by lessthanoptimal.

the class BaseCalibrationConfig method parseTarget.

protected void parseTarget(String where) throws FileNotFoundException {
    Reader input = Objects.requireNonNull(media.openFile(where));
    SimpleStringNumberReader reader = new SimpleStringNumberReader('#');
    if (!reader.read(input))
        throw new RuntimeException("Parsing configuration failed");
    if (reader.remainingTokens() < 7)
        throw new RuntimeException("Not enough tokens in config file");
    String type = reader.nextString();
    numRadial = (int) reader.nextDouble();
    includeTangential = Boolean.parseBoolean(reader.nextString());
    assumeZeroSkew = Boolean.parseBoolean(reader.nextString());
    int numCols = (int) reader.nextDouble();
    int numRows = (int) reader.nextDouble();
    double width = reader.nextDouble();
    if (type.compareToIgnoreCase("square") == 0) {
        double space = reader.nextDouble();
        detector = FactoryFiducialCalibration.squareGrid(null, new ConfigGridDimen(numRows, numCols, width, space));
    } else if (type.compareToIgnoreCase("chess") == 0) {
        detector = FactoryFiducialCalibration.chessboardX((ConfigChessboardX) null, new ConfigGridDimen(numRows, numCols, width));
    } else {
        throw new RuntimeException("Unknown type: " + type);
    }
    try {
        input.close();
    } catch (IOException ignore) {
    }
}
Also used : ConfigGridDimen(boofcv.abst.fiducial.calib.ConfigGridDimen) SimpleStringNumberReader(boofcv.io.SimpleStringNumberReader) Reader(java.io.Reader) SimpleStringNumberReader(boofcv.io.SimpleStringNumberReader) IOException(java.io.IOException)

Example 4 with ConfigGridDimen

use of boofcv.abst.fiducial.calib.ConfigGridDimen in project BoofCV by lessthanoptimal.

the class TestCreateCalibrationTarget method circle_hexagonal.

@Test
void circle_hexagonal() throws IOException {
    createDocument("-r 8 -c 7 -o target -t CIRCLE_HEXAGONAL -u cm -w 2 -d 3 -p LETTER");
    BufferedImage image = loadPDF();
    GrayF32 gray = new GrayF32(image.getWidth(), image.getHeight());
    ConvertBufferedImage.convertFrom(image, gray);
    CalibrationDetectorCircleHexagonalGrid detector = FactoryFiducialCalibration.circleHexagonalGrid(null, new ConfigGridDimen(8, 7, 2, 3));
    assertTrue(detector.process(gray));
}
Also used : ConfigGridDimen(boofcv.abst.fiducial.calib.ConfigGridDimen) GrayF32(boofcv.struct.image.GrayF32) CalibrationDetectorCircleHexagonalGrid(boofcv.abst.fiducial.calib.CalibrationDetectorCircleHexagonalGrid) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) Test(org.junit.jupiter.api.Test)

Example 5 with ConfigGridDimen

use of boofcv.abst.fiducial.calib.ConfigGridDimen 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)

Aggregations

ConfigGridDimen (boofcv.abst.fiducial.calib.ConfigGridDimen)12 GrayF32 (boofcv.struct.image.GrayF32)8 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)7 BufferedImage (java.awt.image.BufferedImage)7 DetectSingleFiducialCalibration (boofcv.abst.geo.calibration.DetectSingleFiducialCalibration)4 Test (org.junit.jupiter.api.Test)4 CalibrateMonoPlanar (boofcv.abst.geo.calibration.CalibrateMonoPlanar)2 CameraPinholeBrown (boofcv.struct.calib.CameraPinholeBrown)2 GrayU8 (boofcv.struct.image.GrayU8)2 CalibrationDetectorChessboardX (boofcv.abst.fiducial.calib.CalibrationDetectorChessboardX)1 CalibrationDetectorCircleHexagonalGrid (boofcv.abst.fiducial.calib.CalibrationDetectorCircleHexagonalGrid)1 CalibrationDetectorSquareGrid (boofcv.abst.fiducial.calib.CalibrationDetectorSquareGrid)1 ConfigECoCheckMarkers (boofcv.abst.fiducial.calib.ConfigECoCheckMarkers)1 LensDistortionNarrowFOV (boofcv.alg.distort.LensDistortionNarrowFOV)1 LensDistortionBrown (boofcv.alg.distort.brown.LensDistortionBrown)1 ECoCheckGenerator (boofcv.alg.fiducial.calib.ecocheck.ECoCheckGenerator)1 ECoCheckUtils (boofcv.alg.fiducial.calib.ecocheck.ECoCheckUtils)1 HammingChessboardGenerator (boofcv.alg.fiducial.calib.hammingchess.HammingChessboardGenerator)1 HammingGridGenerator (boofcv.alg.fiducial.calib.hamminggrids.HammingGridGenerator)1 CalibrationObservation (boofcv.alg.geo.calibration.CalibrationObservation)1