Search in sources :

Example 6 with ConfigChessboard

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

the class ExampleDetectCalibrationPoints method main.

public static void main(String[] args) {
    // load the test image
    // String directory = UtilIO.pathExample("calibration/stereo/Bumblebee2_Square");
    String directory = UtilIO.pathExample("calibration/stereo/Bumblebee2_Chess");
    BufferedImage orig = UtilImageIO.loadImage(directory + "/left01.jpg");
    GrayF32 input = ConvertBufferedImage.convertFrom(orig, (GrayF32) null);
    // To select different types of detectors add or remove comments below
    DetectorFiducialCalibration detector;
    // For chessboard targets, tune RADIUS parameter for your images
    // detector = FactoryCalibrationTarget.squareGrid(new ConfigSquareGrid(4, 3, 30, 30));
    detector = FactoryFiducialCalibration.chessboard(new ConfigChessboard(7, 5, 30));
    // process the image and check for failure condition
    if (!detector.process(input))
        throw new RuntimeException("Target detection failed!");
    // Ordered observations of calibration points on the target
    CalibrationObservation set = detector.getDetectedPoints();
    // render and display the results
    Graphics2D g2 = orig.createGraphics();
    for (PointIndex2D_F64 p : set.points) VisualizeFeatures.drawPoint(g2, p.x, p.y, 3, Color.RED, true);
    ShowImages.showWindow(orig, "Calibration Points", true);
}
Also used : DetectorFiducialCalibration(boofcv.abst.geo.calibration.DetectorFiducialCalibration) GrayF32(boofcv.struct.image.GrayF32) PointIndex2D_F64(boofcv.struct.geo.PointIndex2D_F64) ConfigChessboard(boofcv.abst.fiducial.calib.ConfigChessboard) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) CalibrationObservation(boofcv.alg.geo.calibration.CalibrationObservation)

Example 7 with ConfigChessboard

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

the class CameraCalibration method parseChessboard.

protected void parseChessboard(int index, String[] args) {
    int numRows = 0, numColumns = 0;
    for (; index < args.length; index++) {
        String arg = args[index];
        if (!arg.startsWith("--")) {
            throw new RuntimeException("Expected flags for chessboard.  Should start with '--'");
        }
        splitFlag(arg);
        if (flagName.compareToIgnoreCase("Grid") == 0) {
            String[] words = parameters.split(":");
            if (words.length != 2)
                throw new RuntimeException("Expected two values for rows and columns");
            numRows = Integer.parseInt(words[0]);
            numColumns = Integer.parseInt(words[1]);
        } else {
            throw new RuntimeException("Unknown image option " + flagName);
        }
    }
    if (numRows <= 0 || numColumns <= 0) {
        throw new RuntimeException("Rows and columns must be specified and > 0");
    }
    System.out.println("chessboard: " + numRows + " x " + numColumns);
    ConfigChessboard config = new ConfigChessboard(numRows, numColumns, 1);
    detector = FactoryFiducialCalibration.chessboard(config);
}
Also used : ConfigChessboard(boofcv.abst.fiducial.calib.ConfigChessboard)

Example 8 with ConfigChessboard

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

the class CreateCalibrationTargetGui method updatePreview.

private void updatePreview() {
    double paperWidth = paper.unit.convert(paper.width, units);
    double paperHeight = paper.unit.convert(paper.height, units);
    final RenderCalibrationTargetsGraphics2D renderer = new RenderCalibrationTargetsGraphics2D(-1, 400 / paperWidth);
    renderer.setPaperSize(paperWidth, paperHeight);
    if (selectedType == CalibrationTargetPanel.TargetType.CHESSBOARD) {
        ConfigChessboard config = (ConfigChessboard) selectedCalib;
        renderer.chessboard(config.numRows, config.numCols, config.squareWidth);
    } else if (selectedType == CalibrationTargetPanel.TargetType.SQUARE_GRID) {
        ConfigSquareGrid config = (ConfigSquareGrid) selectedCalib;
        renderer.squareGrid(config.numRows, config.numCols, config.squareWidth, config.spaceWidth);
    } else if (selectedType == CalibrationTargetPanel.TargetType.CIRCLE_GRID) {
        ConfigCircleRegularGrid config = (ConfigCircleRegularGrid) selectedCalib;
        renderer.circleRegular(config.numRows, config.numCols, config.circleDiameter, config.centerDistance);
    } else if (selectedType == CalibrationTargetPanel.TargetType.CIRCLE_HEX) {
        ConfigCircleHexagonalGrid config = (ConfigCircleHexagonalGrid) selectedCalib;
        renderer.circleHex(config.numRows, config.numCols, config.circleDiameter, config.centerDistance);
    }
    renderingPanel.setImageUI(renderer.getBufferred());
}
Also used : ConfigSquareGrid(boofcv.abst.fiducial.calib.ConfigSquareGrid) RenderCalibrationTargetsGraphics2D(boofcv.gui.RenderCalibrationTargetsGraphics2D) ConfigCircleHexagonalGrid(boofcv.abst.fiducial.calib.ConfigCircleHexagonalGrid) ConfigChessboard(boofcv.abst.fiducial.calib.ConfigChessboard) ConfigCircleRegularGrid(boofcv.abst.fiducial.calib.ConfigCircleRegularGrid)

Example 9 with ConfigChessboard

use of boofcv.abst.fiducial.calib.ConfigChessboard 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);
    ConfigChessboard config = new ConfigChessboard(rows, cols, width);
    detector = FactoryFiducial.calibChessboard(config, GrayU8.class);
}
Also used : ConfigChessboard(boofcv.abst.fiducial.calib.ConfigChessboard) GrayU8(boofcv.struct.image.GrayU8)

Example 10 with ConfigChessboard

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

the class TestDetectChessboardFiducial method basicTest.

public void basicTest(int numRows, int numCols, boolean localThreshold) {
    GrayF32 gray = renderTarget(numRows, numCols);
    ImageMiscOps.addGaussian(gray, rand, 0.1, 0, 255);
    // ShowImages.showWindow(gray,"Rendered Image");
    // try { Thread.sleep(1000); } catch (InterruptedException e) {}
    ConfigChessboard configChess = new ConfigChessboard(5, 5, 1);
    DetectPolygonBinaryGrayRefine<GrayF32> detectorSquare = FactoryShapeDetector.polygon(configChess.square, GrayF32.class);
    // detectorSquare.setVerbose(true);
    InputToBinary<GrayF32> inputToBinary;
    if (localThreshold) {
        if (!configChess.thresholding.type.isAdaptive())
            throw new RuntimeException("This assumes that the default is local. Update unit test by specifying a local");
        inputToBinary = FactoryThresholdBinary.threshold(configChess.thresholding, GrayF32.class);
    } else
        inputToBinary = FactoryThresholdBinary.globalFixed(50, true, GrayF32.class);
    DetectChessboardFiducial alg = new DetectChessboardFiducial(numRows, numCols, ConfigLength.fixed(4), detectorSquare, inputToBinary);
    if (!alg.process(gray)) {
        UtilImageIO.saveImage(gray, "savedchessboard.png");
    }
    assertTrue(alg.process(gray));
    List<Point2D_F64> found = alg.getCalibrationPoints();
    List<Point2D_F64> expected = calibrationPoints(numRows, numCols);
    assertEquals(expected.size(), found.size());
    // check the ordering of the points
    for (int i = 0; i < expected.size(); i++) {
        Point2D_F64 e = expected.get(i);
        Point2D_F64 f = found.get(i);
        if (transform != null) {
            SePointOps_F64.transform(transform, e, e);
        }
        assertEquals("i = " + i, e.x, f.x, 2);
        assertEquals("i = " + i, e.y, f.y, 2);
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) Point2D_F64(georegression.struct.point.Point2D_F64) ConfigChessboard(boofcv.abst.fiducial.calib.ConfigChessboard)

Aggregations

ConfigChessboard (boofcv.abst.fiducial.calib.ConfigChessboard)14 DetectorFiducialCalibration (boofcv.abst.geo.calibration.DetectorFiducialCalibration)6 GrayF32 (boofcv.struct.image.GrayF32)5 ConfigSquareGrid (boofcv.abst.fiducial.calib.ConfigSquareGrid)4 ConfigCircleHexagonalGrid (boofcv.abst.fiducial.calib.ConfigCircleHexagonalGrid)3 ConfigCircleRegularGrid (boofcv.abst.fiducial.calib.ConfigCircleRegularGrid)3 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)3 BufferedImage (java.awt.image.BufferedImage)3 CalibrateMonoPlanar (boofcv.abst.geo.calibration.CalibrateMonoPlanar)2 RenderCalibrationTargetsGraphics2D (boofcv.gui.RenderCalibrationTargetsGraphics2D)2 CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)2 Point2D_F64 (georegression.struct.point.Point2D_F64)2 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 LensDistortionNarrowFOV (boofcv.alg.distort.LensDistortionNarrowFOV)1 LensDistortionRadialTangential (boofcv.alg.distort.radtan.LensDistortionRadialTangential)1 CalibrationObservation (boofcv.alg.geo.calibration.CalibrationObservation)1 MousePauseHelper (boofcv.gui.MousePauseHelper)1 PanelGridPanel (boofcv.gui.PanelGridPanel)1