Search in sources :

Example 1 with CalibrateMonoPlanar

use of boofcv.abst.geo.calibration.CalibrateMonoPlanar in project BoofCV by lessthanoptimal.

the class CalibratePinholePlanarGuiApp method configure.

public void configure(DetectorFiducialCalibration detector, List<String> images, int numRadial, boolean includeTangential) {
    this.detector = detector;
    if (images.size() == 0)
        throw new IllegalArgumentException("No images!");
    BoofMiscOps.sortFileNames(images);
    calibrator = new CalibrateMonoPlanar(detector.getLayout());
    calibrator.configurePinhole(true, numRadial, includeTangential);
    this.images = images;
}
Also used : CalibrateMonoPlanar(boofcv.abst.geo.calibration.CalibrateMonoPlanar)

Example 2 with CalibrateMonoPlanar

use of boofcv.abst.geo.calibration.CalibrateMonoPlanar 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 3 with CalibrateMonoPlanar

use of boofcv.abst.geo.calibration.CalibrateMonoPlanar in project BoofCV by lessthanoptimal.

the class ExampleCalibrateMonocular method main.

public static void main(String[] args) {
    DetectorFiducialCalibration detector;
    List<String> images;
    // Regular Circle Example
    // detector = FactoryFiducialCalibration.circleRegularGrid(new ConfigCircleRegularGrid(8, 10, 1.5, 2.5));
    // images = UtilIO.listByPrefix(UtilIO.pathExample("calibration/mono/Sony_DSC-HX5V_CircleRegular"),"image");
    // Hexagonal Circle Example
    // detector = FactoryFiducialCalibration.circleHexagonalGrid(new ConfigCircleHexagonalGrid(24, 28, 1, 1.2));
    // images = UtilIO.listByPrefix(UtilIO.pathExample("calibration/mono/Sony_DSC-HX5V_CircleHexagonal"),"image");
    // Square Grid example
    // detector = FactoryFiducialCalibration.squareGrid(new ConfigSquareGrid(4, 3, 30, 30));
    // images = UtilIO.listByPrefix(UtilIO.pathExample("calibration/stereo/Bumblebee2_Square"),"left");
    // Chessboard Example
    detector = FactoryFiducialCalibration.chessboard(new ConfigChessboard(7, 5, 30));
    images = UtilIO.listByPrefix(UtilIO.pathExample("calibration/stereo/Bumblebee2_Chess"), "left");
    // Declare and setup the calibration algorithm
    CalibrateMonoPlanar calibrationAlg = new CalibrateMonoPlanar(detector.getLayout());
    // tell it type type of target and which parameters to estimate
    calibrationAlg.configurePinhole(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
    CameraPinholeRadial intrinsic = calibrationAlg.process();
    // save results to a file and print out
    CalibrationIO.save(intrinsic, "intrinsic.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) CameraPinholeRadial(boofcv.struct.calib.CameraPinholeRadial) ConfigChessboard(boofcv.abst.fiducial.calib.ConfigChessboard) CalibrateMonoPlanar(boofcv.abst.geo.calibration.CalibrateMonoPlanar) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 4 with CalibrateMonoPlanar

use of boofcv.abst.geo.calibration.CalibrateMonoPlanar in project BoofCV by lessthanoptimal.

the class CalibrateFisheyePlanarGuiApp method configure.

public CalibrateMonoPlanar configure(DetectorFiducialCalibration detector, List<String> images) {
    this.detector = detector;
    if (images.size() == 0)
        throw new IllegalArgumentException("No images!");
    BoofMiscOps.sortFileNames(images);
    calibrator = new CalibrateMonoPlanar(detector.getLayout());
    this.images = images;
    return calibrator;
}
Also used : CalibrateMonoPlanar(boofcv.abst.geo.calibration.CalibrateMonoPlanar)

Example 5 with CalibrateMonoPlanar

use of boofcv.abst.geo.calibration.CalibrateMonoPlanar in project BoofCV by lessthanoptimal.

the class CameraCalibration method handleDirectory.

protected void handleDirectory() {
    final CalibrateMonoPlanar calibrationAlg = new CalibrateMonoPlanar(detector.getLayout());
    final CalibratedPlanarPanel gui;
    ProcessThread monitor = null;
    switch(modeType) {
        case PINHOLE:
            calibrationAlg.configurePinhole(zeroSkew, numRadial, tangential);
            break;
        case UNIVERSAL:
            calibrationAlg.configureUniversalOmni(zeroSkew, numRadial, tangential);
            break;
        default:
            throw new RuntimeException("Unknown model type: " + modeType);
    }
    if (visualize) {
        switch(modeType) {
            case PINHOLE:
                gui = new MonoPlanarPanel();
                break;
            case UNIVERSAL:
                gui = new FisheyePlanarPanel();
                break;
            default:
                throw new RuntimeException("Unknown model type: " + modeType);
        }
        monitor = new ProcessThread(gui);
        monitor.start();
    } else {
        gui = null;
    }
    File directory = new File(inputDirectory);
    if (!directory.exists()) {
        System.err.println("Input directory doesn't exist!");
        System.err.println("  " + inputDirectory);
        System.exit(0);
    }
    List<File> files = Arrays.asList(directory.listFiles());
    BoofMiscOps.sortFilesByName(files);
    if (files.isEmpty()) {
        System.err.println("No image files found!");
        System.err.println(inputDirectory);
        System.exit(0);
    }
    if (visualize) {
        monitor.setMessage(0, "Loading images");
    }
    final List<File> imagesSuccess = new ArrayList<>();
    final List<File> imagesFailed = new ArrayList<>();
    boolean first = true;
    for (File f : files) {
        if (f.isDirectory() || f.isHidden())
            continue;
        final BufferedImage buffered = UtilImageIO.loadImage(f.getPath());
        if (buffered == null)
            continue;
        GrayF32 image = ConvertBufferedImage.convertFrom(buffered, (GrayF32) null);
        if (visualize) {
            monitor.setMessage(0, f.getName());
            if (first) {
                first = false;
                // should do this more intelligently based on image resolution
                int width = Math.min(1000, image.getWidth());
                int height = Math.min(width * image.height / image.width, image.getHeight());
                gui.mainView.setPreferredSize(new Dimension(width, height));
                gui.showImageProcessed(buffered);
                ShowImages.showWindow(gui, "Monocular Calibration", true);
            } else {
                BoofSwingUtil.invokeNowOrLater(new Runnable() {

                    @Override
                    public void run() {
                        gui.showImageProcessed(buffered);
                    }
                });
            }
        }
        if (!detector.process(image)) {
            imagesFailed.add(f);
            System.err.println("Failed to detect target in " + f.getName());
        } else {
            calibrationAlg.addImage(detector.getDetectedPoints());
            imagesSuccess.add(f);
        }
    }
    if (visualize) {
        monitor.setMessage(1, "Computing intrinsics");
    }
    // process and compute intrinsic parameters
    try {
        final CameraModel intrinsic = calibrationAlg.process();
        if (visualize) {
            monitor.stopThread();
            if (imagesFailed.size() > 0) {
                JOptionPane.showMessageDialog(gui, "Failed to detect in " + imagesFailed.size() + " images");
            }
            SwingUtilities.invokeLater(new Runnable() {

                public void run() {
                    gui.setImages(imagesSuccess);
                    gui.setImagesFailed(imagesFailed);
                    gui.setObservations(calibrationAlg.getObservations());
                    gui.setResults(calibrationAlg.getErrors());
                    gui.setCalibration(calibrationAlg.getZhangParam());
                    gui.setCorrection(intrinsic);
                    gui.repaint();
                }
            });
        }
        calibrationAlg.printStatistics();
        System.out.println();
        System.out.println("--- " + modeType + " Parameters ---");
        System.out.println();
        switch(modeType) {
            case PINHOLE:
                {
                    CameraPinholeRadial m = (CameraPinholeRadial) intrinsic;
                    switch(formatType) {
                        case BOOFCV:
                            CalibrationIO.save(m, outputFileName);
                            break;
                        case OPENCV:
                            UtilOpenCV.save(m, outputFileName);
                            break;
                    }
                    m.print();
                }
                break;
            case UNIVERSAL:
                {
                    CameraUniversalOmni m = (CameraUniversalOmni) intrinsic;
                    CalibrationIO.save(m, outputFileName);
                    m.print();
                }
                break;
            default:
                throw new RuntimeException("Unknown model type. " + modeType);
        }
        System.out.println();
        System.out.println("Save file format " + formatType);
        System.out.println();
    } catch (RuntimeException e) {
        if (visualize)
            BoofSwingUtil.warningDialog(gui, e);
        e.printStackTrace();
        System.exit(1);
    }
}
Also used : CameraModel(boofcv.struct.calib.CameraModel) ArrayList(java.util.ArrayList) FisheyePlanarPanel(boofcv.gui.calibration.FisheyePlanarPanel) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) CalibratedPlanarPanel(boofcv.gui.calibration.CalibratedPlanarPanel) GrayF32(boofcv.struct.image.GrayF32) CameraPinholeRadial(boofcv.struct.calib.CameraPinholeRadial) CameraUniversalOmni(boofcv.struct.calib.CameraUniversalOmni) CalibrateMonoPlanar(boofcv.abst.geo.calibration.CalibrateMonoPlanar) File(java.io.File) MonoPlanarPanel(boofcv.gui.calibration.MonoPlanarPanel)

Aggregations

CalibrateMonoPlanar (boofcv.abst.geo.calibration.CalibrateMonoPlanar)5 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)3 GrayF32 (boofcv.struct.image.GrayF32)3 BufferedImage (java.awt.image.BufferedImage)3 ConfigChessboard (boofcv.abst.fiducial.calib.ConfigChessboard)2 DetectorFiducialCalibration (boofcv.abst.geo.calibration.DetectorFiducialCalibration)2 CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)2 CameraUniversalOmni (boofcv.struct.calib.CameraUniversalOmni)2 CalibratedPlanarPanel (boofcv.gui.calibration.CalibratedPlanarPanel)1 FisheyePlanarPanel (boofcv.gui.calibration.FisheyePlanarPanel)1 MonoPlanarPanel (boofcv.gui.calibration.MonoPlanarPanel)1 CameraModel (boofcv.struct.calib.CameraModel)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1