Search in sources :

Example 11 with CameraUniversalOmni

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

the class GenericPlanarCalibrationDetectorChecks method fisheye_fullview.

/**
 * See if it can detect targets distorted by fisheye lens. Entire target is always seen
 */
@Test
public void fisheye_fullview() {
    CameraUniversalOmni model = CalibrationIO.load(getClass().getResource("fisheye.yaml"));
    SimulatePlanarWorld simulator = new SimulatePlanarWorld();
    simulator.setCamera(model);
    List<Point2D_F64> locations2D = new ArrayList<>();
    GrayF32 pattern = new GrayF32(1, 1);
    for (int i = 0; i < targetConfigs.size(); i++) {
        DetectorFiducialCalibration detector = createDetector(targetConfigs.get(i));
        renderTarget(targetConfigs.get(i), simulatedTargetWidth, pattern, locations2D);
        simulator.resetScene();
        Se3_F64 markerToWorld = new Se3_F64();
        simulator.addTarget(markerToWorld, simulatedTargetWidth, pattern);
        failedToDetect = 0;
        for (int j = 0; j < fisheye_poses.size(); j++) {
            // System.out.println("fisheye pose = "+j);
            markerToWorld.set(fisheye_poses.get(j));
            checkRenderedResults(detector, simulator, locations2D);
        }
    }
    assertTrue(failedToDetect <= fisheyeAllowedFails);
}
Also used : SimulatePlanarWorld(boofcv.simulation.SimulatePlanarWorld) DetectorFiducialCalibration(boofcv.abst.geo.calibration.DetectorFiducialCalibration) GrayF32(boofcv.struct.image.GrayF32) CameraUniversalOmni(boofcv.struct.calib.CameraUniversalOmni) Point2D_F64(georegression.struct.point.Point2D_F64) ArrayList(java.util.ArrayList) Se3_F64(georegression.struct.se.Se3_F64) Test(org.junit.Test)

Example 12 with CameraUniversalOmni

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

the class CalibrateFisheyePlanarGuiApp method process.

public void process(String outputFileName) {
    calibrator.reset();
    final ProcessThread monitor = new ProcessThread();
    monitor.start();
    for (int i = 0; i < images.size(); i++) {
        final File file = new File(images.get(i));
        final BufferedImage orig = media.openImage(images.get(i));
        if (orig != null) {
            GrayF32 input = ConvertBufferedImage.convertFrom(orig, (GrayF32) null);
            if (detector.process(input)) {
                calibrator.addImage(detector.getDetectedPoints());
                SwingUtilities.invokeLater(() -> {
                    gui.addImage(file);
                    gui.repaint();
                    monitor.setMessage(0, file.getName());
                });
            } else {
                System.out.println("Failed to detect image.  " + file.getName());
            }
        } else {
            System.out.println("Failed to load " + images.get(i));
        }
    }
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            gui.setObservations(calibrator.getObservations());
        }
    });
    gui.repaint();
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            monitor.setMessage(1, "Estimating Parameters");
        }
    });
    final CameraUniversalOmni param = calibrator.process();
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            gui.setResults(calibrator.getErrors());
            gui.setCalibration(calibrator.getZhangParam());
        }
    });
    monitor.stopThread();
    if (outputFileName != null)
        CalibrationIO.save(param, outputFileName);
    // tell it how to undistort the image
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            gui.setCorrection(param);
            gui.repaint();
        }
    });
    // print the output
    calibrator.printStatistics();
    System.out.println();
    System.out.println("--- Intrinsic Parameters ---");
    System.out.println();
    param.print();
}
Also used : GrayF32(boofcv.struct.image.GrayF32) CameraUniversalOmni(boofcv.struct.calib.CameraUniversalOmni) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 13 with CameraUniversalOmni

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

the class TestSimulatePlanarWorld method main.

public static void main(String[] args) {
    GrayF32 image = new GrayF32(400, 300);
    GImageMiscOps.fill(image, 255);
    GImageMiscOps.fillRectangle(image, 90, 20, 20, 40, 40);
    GImageMiscOps.fillRectangle(image, 90, 60, 60, 40, 40);
    GImageMiscOps.fillRectangle(image, 90, 100, 20, 40, 40);
    GImageMiscOps.fillRectangle(image, 90, 300, 200, 60, 60);
    Se3_F64 rectToWorld = new Se3_F64();
    rectToWorld.T.set(0, 0, -0.2);
    // ConvertRotation3D_F64.eulerToMatrix(EulerType.XYZ,0,1.0,0,rectToWorld.R);
    rectToWorld = rectToWorld.invert(null);
    Se3_F64 rectToWorld2 = new Se3_F64();
    rectToWorld2.T.set(0, -0.20, 0.3);
    String fisheyePath = UtilIO.pathExample("fisheye/theta/");
    CameraUniversalOmni model = CalibrationIO.load(new File(fisheyePath, "front.yaml"));
    SimulatePlanarWorld alg = new SimulatePlanarWorld();
    alg.setCamera(model);
    alg.addTarget(rectToWorld, 0.3, image);
    alg.addTarget(rectToWorld2, 0.15, image);
    alg.render();
    BufferedImage output = new BufferedImage(model.width, model.height, BufferedImage.TYPE_INT_RGB);
    ConvertBufferedImage.convertTo(alg.getOutput(), output);
    ImagePanel panel = ShowImages.showWindow(output, "Rendered Fisheye", true);
    for (int i = 0; i < 2000; i++) {
        alg.getImageRect(0).rectToWorld.T.x = 0.7 * Math.sin(i * 0.01);
        ConvertRotation3D_F64.eulerToMatrix(EulerType.XYZ, 0, 0, i * 0.05, alg.getImageRect(1).rectToWorld.R);
        alg.render();
        ConvertBufferedImage.convertTo(alg.getOutput(), output);
        panel.repaint();
        BoofMiscOps.sleep(10);
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) CameraUniversalOmni(boofcv.struct.calib.CameraUniversalOmni) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) Se3_F64(georegression.struct.se.Se3_F64) ImagePanel(boofcv.gui.image.ImagePanel)

Example 14 with CameraUniversalOmni

use of boofcv.struct.calib.CameraUniversalOmni 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)

Example 15 with CameraUniversalOmni

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

the class FisheyePlanarPanel method setCalibration.

@Override
public void setCalibration(Zhang99AllParam found) {
    CameraUniversalOmni intrinsic = (CameraUniversalOmni) found.getIntrinsic().getCameraModel();
    String textX = String.format("%5.1f", intrinsic.cx);
    String textY = String.format("%5.1f", intrinsic.cy);
    paramCenterX.setText(textX);
    paramCenterY.setText(textY);
    String textA = String.format("%5.1f", intrinsic.fx);
    String textB = String.format("%5.1f", intrinsic.fy);
    paramFX.setText(textA);
    paramFY.setText(textB);
    if (intrinsic.skew == 0) {
        paramSkew.setText("");
    } else {
        String textC = String.format("%5.1e", intrinsic.skew);
        paramSkew.setText(textC);
    }
    String textD = String.format("%5.1e", intrinsic.mirrorOffset);
    paramOffset.setText(textD);
    String radial = "";
    if (intrinsic.radial != null) {
        for (int i = 0; i < intrinsic.radial.length; i++) {
            radial += String.format("%5.2e", intrinsic.radial[i]);
            if (i != intrinsic.radial.length - 1) {
                radial += "\n";
            }
        }
    }
    paramRadial.setText(radial);
    if (intrinsic.t1 != 0 && intrinsic.t2 != 0)
        paramTangental.setText(String.format("%5.2e\n%5.2e", intrinsic.t1, intrinsic.t2));
    else
        paramTangental.setText("");
}
Also used : CameraUniversalOmni(boofcv.struct.calib.CameraUniversalOmni)

Aggregations

CameraUniversalOmni (boofcv.struct.calib.CameraUniversalOmni)19 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)6 GrayF32 (boofcv.struct.image.GrayF32)6 BufferedImage (java.awt.image.BufferedImage)6 File (java.io.File)6 LensDistortionUniversalOmni (boofcv.alg.distort.universal.LensDistortionUniversalOmni)5 ArrayList (java.util.ArrayList)5 Point2D_F64 (georegression.struct.point.Point2D_F64)3 Test (org.junit.Test)3 CalibrateMonoPlanar (boofcv.abst.geo.calibration.CalibrateMonoPlanar)2 DetectorFiducialCalibration (boofcv.abst.geo.calibration.DetectorFiducialCalibration)2 LensDistortionPinhole (boofcv.alg.distort.pinhole.LensDistortionPinhole)2 GrayU8 (boofcv.struct.image.GrayU8)2 Planar (boofcv.struct.image.Planar)2 Point2D_F32 (georegression.struct.point.Point2D_F32)2 Point3D_F32 (georegression.struct.point.Point3D_F32)2 Point3D_F64 (georegression.struct.point.Point3D_F64)2 Se3_F64 (georegression.struct.se.Se3_F64)2 ConfigChessboard (boofcv.abst.fiducial.calib.ConfigChessboard)1 LensDistortionWideFOV (boofcv.alg.distort.LensDistortionWideFOV)1