Search in sources :

Example 6 with CameraPinhole

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

the class TestPerspectiveOps method matrixToParam.

@Test
public void matrixToParam() {
    double fx = 1;
    double fy = 2;
    double skew = 3;
    double cx = 4;
    double cy = 5;
    DMatrixRMaj K = new DMatrixRMaj(3, 3, true, fx, skew, cx, 0, fy, cy, 0, 0, 1);
    CameraPinhole ret = PerspectiveOps.matrixToParam(K, 100, 200, null);
    assertTrue(ret.fx == fx);
    assertTrue(ret.fy == fy);
    assertTrue(ret.skew == skew);
    assertTrue(ret.cx == cx);
    assertTrue(ret.cy == cy);
    assertTrue(ret.width == 100);
    assertTrue(ret.height == 200);
}
Also used : DMatrixRMaj(org.ejml.data.DMatrixRMaj) CameraPinhole(boofcv.struct.calib.CameraPinhole) Test(org.junit.Test)

Example 7 with CameraPinhole

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

the class TestPinholeToEquirectangular_F64 method setDirection.

/**
 * Rotate the camera and see if the camera center is pointing in the right direction now
 */
@Test
public void setDirection() {
    CameraPinhole intrinsic = new CameraPinhole(400, 400, 0, imgWidth / 2, imgHeight / 2, imgWidth, imgHeight);
    PinholeToEquirectangular_F64 alg = new PinholeToEquirectangular_F64();
    alg.setPinhole(intrinsic);
    alg.setEquirectangularShape(equiWidth, equiHeight);
    alg.setDirection(0, Math.PI / 2, 0);
    assertPointing(alg, imgWidth / 2, imgHeight / 2, 1, 0, 0);
}
Also used : CameraPinhole(boofcv.struct.calib.CameraPinhole) Test(org.junit.Test)

Example 8 with CameraPinhole

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

the class ImplPerspectiveOps_F64 method matrixToParam.

public static <C extends CameraPinhole> C matrixToParam(DMatrixRMaj K, int width, int height, C param) {
    if (param == null)
        param = (C) new CameraPinhole();
    param.fx = K.get(0, 0);
    param.fy = K.get(1, 1);
    param.skew = K.get(0, 1);
    param.cx = K.get(0, 2);
    param.cy = K.get(1, 2);
    param.width = width;
    param.height = height;
    return param;
}
Also used : CameraPinhole(boofcv.struct.calib.CameraPinhole)

Example 9 with CameraPinhole

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

the class VisualizeSquareBinaryFiducial method process.

public void process(String nameImage, @Nullable String nameIntrinsic) {
    CameraPinholeBrown intrinsic = nameIntrinsic == null ? null : (CameraPinholeBrown) CalibrationIO.load(nameIntrinsic);
    GrayF32 input = Objects.requireNonNull(UtilImageIO.loadImage(nameImage, GrayF32.class));
    var undistorted = new GrayF32(input.width, input.height);
    InputToBinary<GrayF32> inputToBinary = FactoryThresholdBinary.globalOtsu(0, 255, 1.0, true, GrayF32.class);
    Detector detector = new Detector(gridWidth, borderWidth, inputToBinary);
    detector.setLengthSide(0.1);
    if (intrinsic != null) {
        CameraPinholeBrown paramUndist = new CameraPinholeBrown();
        ImageDistort<GrayF32, GrayF32> undistorter = LensDistortionOps.changeCameraModel(AdjustmentType.EXPAND, BorderType.EXTENDED, intrinsic, new CameraPinhole(intrinsic), paramUndist, ImageType.single(GrayF32.class));
        detector.configure(new LensDistortionBrown(paramUndist), paramUndist.width, paramUndist.height, false);
        undistorter.apply(input, undistorted);
        detector.process(undistorted);
    } else {
        detector.process(input);
    }
    System.out.println("Total Found: " + detector.squares.size());
    DogArray<FoundFiducial> fiducials = detector.getFound();
    int N = Math.min(20, detector.squares.size());
    ListDisplayPanel squares = new ListDisplayPanel();
    for (int i = 0; i < N; i++) {
        squares.addImage(VisualizeBinaryData.renderBinary(detector.squares.get(i), false, null), " " + i);
        squares.addImage(ConvertBufferedImage.convertTo(detector.squaresGray.get(i), null), " " + i);
    }
    BufferedImage output = new BufferedImage(input.width, input.height, BufferedImage.TYPE_INT_RGB);
    ConvertBufferedImage.convertTo(input, output);
    Graphics2D g2 = output.createGraphics();
    g2.setColor(Color.RED);
    g2.setStroke(new BasicStroke(2));
    for (int i = 0; i < N; i++) {
        VisualizeShapes.drawArrowSubPixel(fiducials.get(i).distortedPixels, 3, 1, g2);
    }
    ShowImages.showWindow(output, "Binary", true);
    ShowImages.showWindow(squares, "Candidates", true);
}
Also used : ListDisplayPanel(boofcv.gui.ListDisplayPanel) CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) LensDistortionBrown(boofcv.alg.distort.brown.LensDistortionBrown) FoundFiducial(boofcv.alg.fiducial.square.FoundFiducial) CameraPinhole(boofcv.struct.calib.CameraPinhole) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) GrayF32(boofcv.struct.image.GrayF32) FactoryShapeDetector(boofcv.factory.shape.FactoryShapeDetector) ConfigPolygonDetector(boofcv.factory.shape.ConfigPolygonDetector)

Example 10 with CameraPinhole

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

the class RefineTwoViewPinholeRotation method refine.

/**
 * Refines the provided parameters. Inputs are only modified if it returns true. If two views are specified
 * but there's a single view assumption then only the first view is used.
 *
 * @param associatedPixels (Input) Matches image features between the two views. Pixels.
 * @param rotation (Input/Output) Initial estimate of rotation. Results are written to it.
 * @param intrinsic1 (Input/Output) Initial estimate of intrinsic1. Results are written to it.
 * @param intrinsic2 (Input/Output) Initial estimate of intrinsic2. Results are written to it.
 * @return true if it thinks it has a valid solution. False if it knows it failed.
 */
public boolean refine(List<AssociatedPair> associatedPixels, DMatrixRMaj rotation, CameraPinhole intrinsic1, CameraPinhole intrinsic2) {
    this.associatedPixels = associatedPixels;
    this.inputIntrinsic1 = intrinsic1;
    this.inputIntrinsic2 = intrinsic2;
    // Copy inputs over
    ConvertRotation3D_F64.matrixToRodrigues(rotation, function.state.rotation);
    function.state.intrinsic1.setTo(intrinsic1);
    function.state.intrinsic2.setTo(intrinsic2);
    initialParameters.resize(function.getNumOfInputsN());
    function.state.encode(initialParameters.data);
    // Configure the minimization
    minimizer.setFunction(function, new NumericalJacobianForward_DDRM(new ResidualFunction()));
    minimizer.initialize(initialParameters.data, converge.ftol, converge.gtol);
    errorBefore = minimizer.getFunctionValue();
    // Iterate until a final condition has been met
    int iterations;
    for (iterations = 0; iterations < converge.maxIterations; iterations++) {
        if (minimizer.iterate())
            break;
    }
    errorAfter = minimizer.getFunctionValue();
    // Get the refined values
    function.state.decode(minimizer.getParameters());
    if (verbose != null) {
        double theta = UtilAngle.degree(function.state.rotation.theta);
        CameraPinhole found1 = function.state.intrinsic1;
        CameraPinhole found2 = function.state.intrinsic2;
        verbose.printf("before=%.2e after=%.2e iterations=%d converged=%s, " + "view1={fx=%.1f fy=%.1f, cx=%.1f cy=%.1f), " + "view2=(fx=%.1f fy=%.1f, cx=%.1f cy=%.1f) theta=%.2f\n", errorBefore, errorAfter, iterations, minimizer.isConverged(), found1.fx, found1.fy, found1.cx, found1.cy, found2.fx, found2.fy, found2.cx, found2.cy, theta);
    }
    // Copy results
    intrinsic1.setTo(function.state.intrinsic1);
    intrinsic2.setTo(function.state.intrinsic2);
    ConvertRotation3D_F64.rodriguesToMatrix(function.state.rotation, rotation);
    return true;
}
Also used : NumericalJacobianForward_DDRM(org.ddogleg.optimization.derivative.NumericalJacobianForward_DDRM) CameraPinhole(boofcv.struct.calib.CameraPinhole) VerbosePrint(org.ddogleg.struct.VerbosePrint)

Aggregations

CameraPinhole (boofcv.struct.calib.CameraPinhole)154 Test (org.junit.jupiter.api.Test)81 Se3_F64 (georegression.struct.se.Se3_F64)36 DMatrixRMaj (org.ejml.data.DMatrixRMaj)32 Point2D_F64 (georegression.struct.point.Point2D_F64)24 ArrayList (java.util.ArrayList)23 Point3D_F64 (georegression.struct.point.Point3D_F64)19 Homography2D_F64 (georegression.struct.homography.Homography2D_F64)12 SceneStructureMetric (boofcv.abst.geo.bundle.SceneStructureMetric)11 CameraPinholeBrown (boofcv.struct.calib.CameraPinholeBrown)11 Test (org.junit.Test)10 GrayF32 (boofcv.struct.image.GrayF32)9 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)8 Point2Transform2_F32 (boofcv.struct.distort.Point2Transform2_F32)8 BufferedImage (java.awt.image.BufferedImage)8 Point2Transform2_F64 (boofcv.struct.distort.Point2Transform2_F64)7 VerbosePrint (org.ddogleg.struct.VerbosePrint)7 LensDistortionPinhole (boofcv.alg.distort.pinhole.LensDistortionPinhole)6 WorldToCameraToPixel (boofcv.alg.geo.WorldToCameraToPixel)6 CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)5