Search in sources :

Example 1 with CalibrationObservation

use of boofcv.alg.geo.calibration.CalibrationObservation in project BoofCV by lessthanoptimal.

the class DisplayPinholeCalibrationPanel method drawFeatures.

private void drawFeatures(Graphics2D g2, double scale) {
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    CalibrationObservation set = features;
    Point2D_F32 adj = new Point2D_F32();
    if (showOrder) {
        List<Point2D_F64> adjusted;
        if (showUndistorted) {
            adjusted = new ArrayList<>();
            for (PointIndex2D_F64 p : set.points) {
                remove_p_to_p.compute((float) p.x, (float) p.y, adj);
                adjusted.add(new Point2D_F64(adj.x, adj.y));
            }
        } else {
            adjusted = (List) set.points;
        }
        renderOrder(g2, scale, adjusted);
    }
    if (showPoints) {
        g2.setColor(Color.BLACK);
        g2.setStroke(new BasicStroke(3));
        for (PointIndex2D_F64 p : set.points) {
            if (showUndistorted) {
                remove_p_to_p.compute((float) p.x, (float) p.y, adj);
            } else {
                adj.set((float) p.x, (float) p.y);
            }
            VisualizeFeatures.drawCross(g2, adj.x * scale, adj.y * scale, 4);
        }
        g2.setStroke(new BasicStroke(1));
        g2.setColor(Color.RED);
        for (PointIndex2D_F64 p : set.points) {
            if (showUndistorted) {
                remove_p_to_p.compute((float) p.x, (float) p.y, adj);
            } else {
                adj.set((float) p.x, (float) p.y);
            }
            VisualizeFeatures.drawCross(g2, adj.x * scale, adj.y * scale, 4);
        }
    }
    if (showAll) {
        for (CalibrationObservation l : allFeatures) {
            for (PointIndex2D_F64 p : l.points) {
                if (showUndistorted) {
                    remove_p_to_p.compute((float) p.x, (float) p.y, adj);
                } else {
                    adj.set((float) p.x, (float) p.y);
                }
                VisualizeFeatures.drawPoint(g2, adj.x * scale, adj.y * scale, 2, Color.BLUE, false);
            }
        }
    }
    if (showNumbers) {
        if (showUndistorted)
            drawNumbers(g2, set, remove_p_to_p, scale);
        else
            drawNumbers(g2, set, null, scale);
    }
    if (showErrors && results != null) {
        for (int i = 0; i < set.size(); i++) {
            PointIndex2D_F64 p = set.get(i);
            if (showUndistorted) {
                remove_p_to_p.compute((float) p.x, (float) p.y, adj);
            } else {
                adj.set((float) p.x, (float) p.y);
            }
            double r = scale * errorScale * results.pointError[i];
            if (r < 1)
                continue;
            g2.setStroke(new BasicStroke(4));
            g2.setColor(Color.BLACK);
            VisualizeFeatures.drawCircle(g2, adj.x * scale, adj.y * scale, r);
            g2.setStroke(new BasicStroke(2.5f));
            g2.setColor(Color.ORANGE);
            VisualizeFeatures.drawCircle(g2, adj.x * scale, adj.y * scale, r);
        }
    }
}
Also used : Point2D_F64(georegression.struct.point.Point2D_F64) PointIndex2D_F64(boofcv.struct.geo.PointIndex2D_F64) Point2D_F32(georegression.struct.point.Point2D_F32) CalibrationObservation(boofcv.alg.geo.calibration.CalibrationObservation)

Example 2 with CalibrationObservation

use of boofcv.alg.geo.calibration.CalibrationObservation in project BoofCV by lessthanoptimal.

the class CalibrateStereoPlanarGuiApp method process.

public void process(String outputFileName) {
    // displays progress so the impatient don't give up
    final ProcessThread monitor = new ProcessThread();
    monitor.start();
    // load images
    calibrator.reset();
    int N = leftImages.size();
    for (int i = 0; i < N; i++) {
        final BufferedImage leftOrig = media.openImage(leftImages.get(i).getPath());
        final BufferedImage rightOrig = media.openImage(rightImages.get(i).getPath());
        if (leftOrig != null && rightOrig != null) {
            GrayF32 leftInput = ConvertBufferedImage.convertFrom(leftOrig, (GrayF32) null);
            GrayF32 rightInput = ConvertBufferedImage.convertFrom(rightOrig, (GrayF32) null);
            CalibrationObservation calibLeft, calibRight;
            if (!detector.process(leftInput)) {
                System.out.println("Feature detection failed in " + leftImages.get(i));
                continue;
            }
            calibLeft = detector.getDetectedPoints();
            if (!detector.process(rightInput)) {
                System.out.println("Feature detection failed in " + rightImages.get(i));
                continue;
            }
            calibRight = detector.getDetectedPoints();
            calibrator.addPair(calibLeft, calibRight);
            final int number = i;
            SwingUtilities.invokeLater(() -> {
                gui.addPair("Image " + number, leftImages.get(number), rightImages.get(number));
                gui.repaint();
                monitor.setMessage(0, "Image " + number);
            });
        } else {
            System.out.println("Failed to load left  = " + leftImages.get(i));
            System.out.println("Failed to load right = " + rightImages.get(i));
        }
    }
    // SwingUtilities.invokeLater(new Runnable() {
    // public void run() {
    // gui.setObservations(calibrator.getCalibLeft().getObservations(),calibrator.getCalibLeft().getErrors(),
    // calibrator.getCalibRight().getObservations(),calibrator.getCalibRight().getErrors());
    // }});
    // gui.repaint();
    SwingUtilities.invokeLater(new Runnable() {

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

        public void run() {
            gui.setObservations(calibrator.getCalibLeft().getObservations(), calibrator.getCalibLeft().getErrors(), calibrator.getCalibRight().getObservations(), calibrator.getCalibRight().getErrors());
        }
    });
    gui.repaint();
    // compute stereo rectification
    setRectification(param);
    monitor.stopThread();
    calibrator.printStatistics();
    param.print();
    if (outputFileName != null)
        CalibrationIO.save(param, outputFileName);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) StereoParameters(boofcv.struct.calib.StereoParameters) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) CalibrationObservation(boofcv.alg.geo.calibration.CalibrationObservation)

Example 3 with CalibrationObservation

use of boofcv.alg.geo.calibration.CalibrationObservation in project BoofCV by lessthanoptimal.

the class GenericPlanarCalibrationDetectorChecks method dataNotRecycled.

/**
 * Make sure new instances of calibration points are returned each time
 */
@Test
public void dataNotRecycled() {
    for (Object layout : targetConfigs) {
        DetectorFiducialCalibration detector = createDetector(layout);
        GrayF32 original = renderEasy(layout, null);
        assertTrue(detector.process(original));
        CalibrationObservation found0 = detector.getDetectedPoints();
        assertTrue(detector.process(original));
        CalibrationObservation found1 = detector.getDetectedPoints();
        assertEquals(found0.size(), found1.size());
        assertTrue(found0 != found1);
        for (int i = 0; i < found0.size(); i++) {
            PointIndex2D_F64 p0 = found0.get(i);
            for (int j = 0; j < found1.size(); j++) {
                PointIndex2D_F64 p1 = found1.get(j);
                assertFalse(p0 == p1);
            }
        }
    }
}
Also used : DetectorFiducialCalibration(boofcv.abst.geo.calibration.DetectorFiducialCalibration) GrayF32(boofcv.struct.image.GrayF32) PointIndex2D_F64(boofcv.struct.geo.PointIndex2D_F64) CalibrationObservation(boofcv.alg.geo.calibration.CalibrationObservation) Test(org.junit.Test)

Example 4 with CalibrationObservation

use of boofcv.alg.geo.calibration.CalibrationObservation in project BoofCV by lessthanoptimal.

the class ExampleCalibrateStereo method process.

/**
 * Process calibration images, compute intrinsic parameters, save to a file
 */
public void process() {
    // Declare and setup the calibration algorithm
    CalibrateStereoPlanar calibratorAlg = new CalibrateStereoPlanar(detector.getLayout());
    calibratorAlg.configure(true, 2, false);
    // ensure the lists are in the same order
    Collections.sort(left);
    Collections.sort(right);
    for (int i = 0; i < left.size(); i++) {
        BufferedImage l = UtilImageIO.loadImage(left.get(i));
        BufferedImage r = UtilImageIO.loadImage(right.get(i));
        GrayF32 imageLeft = ConvertBufferedImage.convertFrom(l, (GrayF32) null);
        GrayF32 imageRight = ConvertBufferedImage.convertFrom(r, (GrayF32) null);
        CalibrationObservation calibLeft, calibRight;
        if (!detector.process(imageLeft)) {
            System.out.println("Failed to detect target in " + left.get(i));
            continue;
        }
        calibLeft = detector.getDetectedPoints();
        if (!detector.process(imageRight)) {
            System.out.println("Failed to detect target in " + right.get(i));
            continue;
        }
        calibRight = detector.getDetectedPoints();
        calibratorAlg.addPair(calibLeft, calibRight);
    }
    // Process and compute calibration parameters
    StereoParameters stereoCalib = calibratorAlg.process();
    // print out information on its accuracy and errors
    calibratorAlg.printStatistics();
    // save results to a file and print out
    CalibrationIO.save(stereoCalib, "stereo.yaml");
    stereoCalib.print();
// Note that the stereo baseline translation will be specified in the same units as the calibration grid.
// Which is in millimeters (mm) in this example.
}
Also used : CalibrateStereoPlanar(boofcv.abst.geo.calibration.CalibrateStereoPlanar) GrayF32(boofcv.struct.image.GrayF32) StereoParameters(boofcv.struct.calib.StereoParameters) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) CalibrationObservation(boofcv.alg.geo.calibration.CalibrationObservation)

Example 5 with CalibrationObservation

use of boofcv.alg.geo.calibration.CalibrationObservation 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)

Aggregations

CalibrationObservation (boofcv.alg.geo.calibration.CalibrationObservation)16 Point2D_F64 (georegression.struct.point.Point2D_F64)6 PointIndex2D_F64 (boofcv.struct.geo.PointIndex2D_F64)5 GrayF32 (boofcv.struct.image.GrayF32)5 DetectorFiducialCalibration (boofcv.abst.geo.calibration.DetectorFiducialCalibration)3 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)3 BufferedImage (java.awt.image.BufferedImage)3 Grid (boofcv.alg.fiducial.calib.circle.EllipseClustersIntoGrid.Grid)2 StereoParameters (boofcv.struct.calib.StereoParameters)2 Point2D_F32 (georegression.struct.point.Point2D_F32)2 Point3D_F64 (georegression.struct.point.Point3D_F64)2 Se3_F64 (georegression.struct.se.Se3_F64)2 Test (org.junit.Test)2 ConfigChessboard (boofcv.abst.fiducial.calib.ConfigChessboard)1 CalibrateStereoPlanar (boofcv.abst.geo.calibration.CalibrateStereoPlanar)1 DetectFiducialSquareGrid (boofcv.alg.fiducial.calib.DetectFiducialSquareGrid)1 DetectCircleHexagonalGrid (boofcv.alg.fiducial.calib.circle.DetectCircleHexagonalGrid)1 DetectCircleRegularGrid (boofcv.alg.fiducial.calib.circle.DetectCircleRegularGrid)1 KeyPointsCircleHexagonalGrid (boofcv.alg.fiducial.calib.circle.KeyPointsCircleHexagonalGrid)1 KeyPointsCircleRegularGrid (boofcv.alg.fiducial.calib.circle.KeyPointsCircleRegularGrid)1