Search in sources :

Example 86 with CameraPinholeBrown

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

the class GenericQrCodeDetectorChecks method multipleMarkers.

/**
 * See if it can detect multiple fiducials in the image at the same time
 */
@Test
void multipleMarkers() {
    QrCodeDetector<GrayF32> detector = createDetector();
    CameraPinholeBrown model = CalibrationIO.load(getClass().getResource("calib/pinhole_radial.yaml"));
    SimulatePlanarWorld simulator = new SimulatePlanarWorld();
    simulator.setCamera(model);
    simulator.resetScene();
    Se3_F64 markerToWorld0 = new Se3_F64();
    Se3_F64 markerToWorld1 = new Se3_F64();
    simulator.addSurface(markerToWorld0, simulatedTargetWidth, generateMarker());
    simulator.addSurface(markerToWorld1, simulatedTargetWidth, generateMarker());
    ConvertRotation3D_F64.eulerToMatrix(EulerType.XYZ, 0, Math.PI, 0, markerToWorld0.R);
    markerToWorld0.T.setTo(0.2, 0, 0.6);
    ConvertRotation3D_F64.eulerToMatrix(EulerType.XYZ, 0, Math.PI, 0, markerToWorld1.R);
    markerToWorld1.T.setTo(-0.2, 0, 0.6);
    simulator.render();
    detector.process(simulator.getOutput());
    if (display) {
        ShowImages.showWindow(simulator.getOutput(), ShowImages.Colorization.MAGNITUDE, "Foo", true);
        BoofMiscOps.sleep(10000);
    }
    List<QrCode> detections = detector.getDetections();
    assertEquals(2, detections.size());
}
Also used : QrCode(boofcv.alg.fiducial.qrcode.QrCode) SimulatePlanarWorld(boofcv.simulation.SimulatePlanarWorld) GrayF32(boofcv.struct.image.GrayF32) CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) Se3_F64(georegression.struct.se.Se3_F64) Test(org.junit.jupiter.api.Test)

Example 87 with CameraPinholeBrown

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

the class GenericQrCodeDetectorChecks method scale.

/**
 * The marker zooming in and out of the frame
 */
@Test
void scale() {
    QrCodeDetector<GrayF32> detector = createDetector();
    CameraPinholeBrown model = CalibrationIO.load(getClass().getResource("calib/pinhole_radial.yaml"));
    SimulatePlanarWorld simulator = new SimulatePlanarWorld();
    simulator.setCamera(model);
    simulator.resetScene();
    Se3_F64 markerToWorld = new Se3_F64();
    simulator.addSurface(markerToWorld, simulatedTargetWidth, generateMarker());
    ConvertRotation3D_F64.eulerToMatrix(EulerType.XYZ, 0, Math.PI, 0, markerToWorld.R);
    markerToWorld.T.setTo(0, 0, 0.3);
    for (int i = 0; i < 30; i++) {
        renderAndCheck(detector, simulator);
        markerToWorld.T.z += 0.03;
    }
}
Also used : SimulatePlanarWorld(boofcv.simulation.SimulatePlanarWorld) GrayF32(boofcv.struct.image.GrayF32) CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) Se3_F64(georegression.struct.se.Se3_F64) Test(org.junit.jupiter.api.Test)

Example 88 with CameraPinholeBrown

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

the class GenericDetectMultiFiducialCalibrationChecks method basicPinhole.

@Test
void basicPinhole() {
    DetectMultiFiducialCalibration detector = createDetector();
    // CameraPinholeBrown model = CalibrationIO.load(getClass().getResource("pinhole_radial.yaml"));
    CameraPinholeBrown model = new CameraPinholeBrown().fsetK(600, 600, 0, 400, 400, 800, 800);
    SimulatePlanarWorld simulator = new SimulatePlanarWorld();
    simulator.setCamera(model);
    DogArray<List<PointIndex2D_F64>> markerPoints = new DogArray<>(ArrayList::new);
    for (int i = 0; i < Math.min(2, detector.getTotalUniqueMarkers()); i++) {
        GrayF32 pattern = renderPattern(i, markerPoints.grow());
        Se3_F64 markerToWorld = SpecialEuclideanOps_F64.eulerXyz((-0.5 + i) * 0.32, 0, .5, 0, Math.PI, 0, null);
        simulator.addSurface(markerToWorld, simulatedTargetWidth, pattern);
    }
    // marker systems since that requires encoding that should remove that ambiguity
    for (int cameraOriIdx = 0; cameraOriIdx < 10; cameraOriIdx++) {
        double roll = 2.0 * Math.PI * cameraOriIdx / 10;
        simulator.setWorldToCamera(SpecialEuclideanOps_F64.eulerXyz(0, 0, 0, 0, 0, roll, null));
        simulator.render();
        // Process the image and see if it detected everything
        detector.process(simulator.getOutput());
        // ShowImages.showWindow(simulator.getOutput(), "Rotated "+cameraOriIdx);
        // BoofMiscOps.sleep(2_000);
        // Number of markers which are not anonymous
        int totalIdentified = 0;
        for (int i = 0; i < detector.getDetectionCount(); i++) {
            if (detector.getMarkerID(i) >= 0)
                totalIdentified++;
        }
        if (visualizeFailures && 2 != totalIdentified) {
            UtilImageIO.saveImage(simulator.getOutput(), "failed.png");
            ShowImages.showWindow(simulator.getOutput(), "Simulated");
            BoofMiscOps.sleep(10_000);
        }
        assertEquals(2, totalIdentified);
        for (int i = 0; i < detector.getDetectionCount(); i++) {
            int markerID = detector.getMarkerID(i);
            // Ignore anonymous markers
            if (markerID < 0)
                continue;
            // See if it detected the expected number of calibration points on the marker
            assertEquals(markerPoints.get(markerID).size(), detector.getDetectedPoints(i).size());
        // TODO check the actual coordinates
        }
    }
}
Also used : DetectMultiFiducialCalibration(boofcv.abst.geo.calibration.DetectMultiFiducialCalibration) SimulatePlanarWorld(boofcv.simulation.SimulatePlanarWorld) GrayF32(boofcv.struct.image.GrayF32) CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) DogArray(org.ddogleg.struct.DogArray) Se3_F64(georegression.struct.se.Se3_F64) Test(org.junit.jupiter.api.Test)

Example 89 with CameraPinholeBrown

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

the class StereoProcessingBase method setCalibration.

/**
 * Specifies stereo parameters
 *
 * @param stereoParam stereo parameters
 */
public void setCalibration(StereoParameters stereoParam) {
    CameraPinholeBrown left = stereoParam.getLeft();
    CameraPinholeBrown right = stereoParam.getRight();
    // adjust image size
    imageLeftRect.reshape(left.getWidth(), left.getHeight());
    imageRightRect.reshape(right.getWidth(), right.getHeight());
    // compute rectification
    RectifyCalibrated rectifyAlg = RectifyImageOps.createCalibrated();
    Se3_F64 leftToRight = stereoParam.getRightToLeft().invert(null);
    // original camera calibration matrices
    DMatrixRMaj K1 = PerspectiveOps.pinholeToMatrix(left, (DMatrixRMaj) null);
    DMatrixRMaj K2 = PerspectiveOps.pinholeToMatrix(right, (DMatrixRMaj) null);
    rectifyAlg.process(K1, new Se3_F64(), K2, leftToRight);
    // rectification matrix for each image
    rect1 = rectifyAlg.getUndistToRectPixels1();
    rect2 = rectifyAlg.getUndistToRectPixels2();
    // New calibration and rotation matrix, Both cameras are the same after rectification.
    rectK = rectifyAlg.getCalibrationMatrix();
    rectR = rectifyAlg.getRectifiedRotation();
    FMatrixRMaj rect1_F32 = new FMatrixRMaj(3, 3);
    FMatrixRMaj rect2_F32 = new FMatrixRMaj(3, 3);
    ConvertMatrixData.convert(rect1, rect1_F32);
    ConvertMatrixData.convert(rect2, rect2_F32);
    ImageType<T> imageType = imageLeftRect.getImageType();
    distortLeftRect = RectifyDistortImageOps.rectifyImage(stereoParam.left, rect1_F32, BorderType.SKIP, imageType);
    distortRightRect = RectifyDistortImageOps.rectifyImage(stereoParam.right, rect2_F32, BorderType.SKIP, imageType);
    // Compute parameters that are needed when converting to 3D
    baseline = stereoParam.getBaseline();
    fx = rectK.get(0, 0);
    fy = rectK.get(1, 1);
    cx = rectK.get(0, 2);
    cy = rectK.get(1, 2);
}
Also used : FMatrixRMaj(org.ejml.data.FMatrixRMaj) CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) RectifyCalibrated(boofcv.alg.geo.rectify.RectifyCalibrated) DMatrixRMaj(org.ejml.data.DMatrixRMaj) Se3_F64(georegression.struct.se.Se3_F64)

Example 90 with CameraPinholeBrown

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

the class StereoConsistencyCheck method setCalibration.

public void setCalibration(StereoParameters param) {
    CameraPinholeBrown left = param.getLeft();
    CameraPinholeBrown right = param.getRight();
    // compute rectification
    RectifyCalibrated rectifyAlg = RectifyImageOps.createCalibrated();
    Se3_F64 leftToRight = param.getRightToLeft().invert(null);
    // original camera calibration matrices
    DMatrixRMaj K1 = PerspectiveOps.pinholeToMatrix(left, (DMatrixRMaj) null);
    DMatrixRMaj K2 = PerspectiveOps.pinholeToMatrix(right, (DMatrixRMaj) null);
    rectifyAlg.process(K1, new Se3_F64(), K2, leftToRight);
    // rectification matrix for each image
    DMatrixRMaj rect1 = rectifyAlg.getUndistToRectPixels1();
    DMatrixRMaj rect2 = rectifyAlg.getUndistToRectPixels2();
    leftImageToRect = RectifyImageOps.transformPixelToRect(param.left, rect1);
    rightImageToRect = RectifyImageOps.transformPixelToRect(param.right, rect2);
}
Also used : CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) RectifyCalibrated(boofcv.alg.geo.rectify.RectifyCalibrated) DMatrixRMaj(org.ejml.data.DMatrixRMaj) Se3_F64(georegression.struct.se.Se3_F64)

Aggregations

CameraPinholeBrown (boofcv.struct.calib.CameraPinholeBrown)99 Test (org.junit.jupiter.api.Test)62 Se3_F64 (georegression.struct.se.Se3_F64)39 GrayF32 (boofcv.struct.image.GrayF32)29 Point2D_F64 (georegression.struct.point.Point2D_F64)19 SimulatePlanarWorld (boofcv.simulation.SimulatePlanarWorld)16 LensDistortionBrown (boofcv.alg.distort.brown.LensDistortionBrown)14 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)14 BufferedImage (java.awt.image.BufferedImage)14 ArrayList (java.util.ArrayList)12 CameraPinhole (boofcv.struct.calib.CameraPinhole)11 Point2Transform2_F64 (boofcv.struct.distort.Point2Transform2_F64)10 DMatrixRMaj (org.ejml.data.DMatrixRMaj)10 File (java.io.File)9 StereoParameters (boofcv.struct.calib.StereoParameters)6 GrayU8 (boofcv.struct.image.GrayU8)6 Point3D_F64 (georegression.struct.point.Point3D_F64)6 ImageBase (boofcv.struct.image.ImageBase)5 ImageType (boofcv.struct.image.ImageType)5 DogArray (org.ddogleg.struct.DogArray)5