Search in sources :

Example 1 with PinholePtoN_F64

use of boofcv.alg.distort.pinhole.PinholePtoN_F64 in project BoofCV by lessthanoptimal.

the class ResolveSignAmbiguityPositiveDepth method process.

/**
 * Processes the results and observations to fix the sign
 *
 * @param observations (input) Observations in pixels
 * @param result (input/output) the current solution and modified to have the correct sign on output
 */
public void process(List<AssociatedTriple> observations, MetricCameraTriple result) {
    signChanged = false;
    int best = -1;
    bestInvalid = Integer.MAX_VALUE;
    normalizers.resize(3);
    pixelNorms.resize(3);
    worldToViews.resize(3);
    PinholePtoN_F64 normalize1 = normalizers.get(0);
    PinholePtoN_F64 normalize2 = normalizers.get(1);
    PinholePtoN_F64 normalize3 = normalizers.get(2);
    Point2D_F64 n1 = pixelNorms.get(0);
    Point2D_F64 n2 = pixelNorms.get(1);
    Point2D_F64 n3 = pixelNorms.get(2);
    worldToViews.get(1).setTo(result.view_1_to_2);
    worldToViews.get(2).setTo(result.view_1_to_3);
    normalize1.setK(result.view1);
    normalize2.setK(result.view2);
    normalize3.setK(result.view3);
    for (int trial = 0; trial < 2; trial++) {
        int foundInvalid = 0;
        for (int i = 0; i < observations.size(); i++) {
            AssociatedTriple ap = observations.get(i);
            // Convert from pixels to normalized image coordinates
            normalize1.compute(ap.p1.x, ap.p1.y, n1);
            normalize2.compute(ap.p2.x, ap.p2.y, n2);
            normalize2.compute(ap.p3.x, ap.p3.y, n3);
            // Find point in view-1 reference frame and check constraint
            triangulator.triangulate(pixelNorms.toList(), worldToViews.toList(), pointIn1);
            if (PerspectiveOps.isBehindCamera(pointIn1))
                foundInvalid++;
            // Find in view-2 and check +z constraint
            SePointOps_F64.transform(result.view_1_to_2, pointIn1, Xcam);
            if (PerspectiveOps.isBehindCamera(Xcam))
                foundInvalid++;
            // Find in view-3 and check +z constraint
            SePointOps_F64.transform(result.view_1_to_3, pointIn1, Xcam);
            if (PerspectiveOps.isBehindCamera(Xcam))
                foundInvalid++;
        }
        if (verbose != null)
            verbose.println("trial=" + trial + " invalid=" + foundInvalid + " obs=" + observations.size());
        // flip to test other hypothesis next iteration
        for (int i = 1; i < worldToViews.size(); i++) {
            worldToViews.get(i).T.scale(-1);
        }
        // save best
        if (bestInvalid > foundInvalid) {
            bestInvalid = foundInvalid;
            best = trial;
        }
    }
    if (best == 1) {
        signChanged = true;
        result.view_1_to_2.T.scale(-1);
        result.view_1_to_3.T.scale(-1);
    }
    if (verbose != null)
        verbose.println("best=" + best + " signChanged=" + signChanged);
}
Also used : AssociatedTriple(boofcv.struct.geo.AssociatedTriple) PinholePtoN_F64(boofcv.alg.distort.pinhole.PinholePtoN_F64) Point2D_F64(georegression.struct.point.Point2D_F64) VerbosePrint(org.ddogleg.struct.VerbosePrint)

Example 2 with PinholePtoN_F64

use of boofcv.alg.distort.pinhole.PinholePtoN_F64 in project BoofCV by lessthanoptimal.

the class ImplRectifyImageOps_F64 method transformPixelToRectNorm.

public static Point2Transform2_F64 transformPixelToRectNorm(CameraPinholeBrown param, DMatrixRMaj rectify, DMatrixRMaj rectifyK) {
    if (rectifyK.get(0, 1) != 0)
        throw new IllegalArgumentException("Skew should be zero in rectified images");
    Point2Transform2_F64 remove_p_to_p = narrow(param).undistort_F64(true, true);
    PointTransformHomography_F64 rectifyDistort = new PointTransformHomography_F64(rectify);
    PinholePtoN_F64 pixelToNorm = new PinholePtoN_F64();
    pixelToNorm.setK(rectifyK.get(0, 0), rectifyK.get(1, 1), rectifyK.get(0, 1), rectifyK.get(0, 2), rectifyK.get(1, 2));
    return new SequencePoint2Transform2_F64(remove_p_to_p, rectifyDistort, pixelToNorm);
}
Also used : PinholePtoN_F64(boofcv.alg.distort.pinhole.PinholePtoN_F64) PointTransformHomography_F64(boofcv.alg.distort.PointTransformHomography_F64) SequencePoint2Transform2_F64(boofcv.struct.distort.SequencePoint2Transform2_F64) Point2Transform2_F64(boofcv.struct.distort.Point2Transform2_F64) SequencePoint2Transform2_F64(boofcv.struct.distort.SequencePoint2Transform2_F64)

Example 3 with PinholePtoN_F64

use of boofcv.alg.distort.pinhole.PinholePtoN_F64 in project BoofCV by lessthanoptimal.

the class ImplPerspectiveOps_F64 method convertPixelToNorm.

public static Point2D_F64 convertPixelToNorm(DMatrixRMaj K, Point2D_F64 pixel, @Nullable Point2D_F64 norm) {
    if (norm == null)
        norm = new Point2D_F64();
    PinholePtoN_F64 alg = new PinholePtoN_F64();
    alg.setK(K.get(0, 0), K.get(1, 1), K.get(0, 1), K.get(0, 2), K.get(1, 2));
    alg.compute(pixel.x, pixel.y, norm);
    return norm;
}
Also used : Point2D_F64(georegression.struct.point.Point2D_F64) PinholePtoN_F64(boofcv.alg.distort.pinhole.PinholePtoN_F64)

Example 4 with PinholePtoN_F64

use of boofcv.alg.distort.pinhole.PinholePtoN_F64 in project BoofCV by lessthanoptimal.

the class PinholeToEquirectangular_F64 method setPinhole.

/**
 * Specifies the pinhole camera
 * @param pinhole intrinsic parameters of pinhole camera
 */
public void setPinhole(CameraPinhole pinhole) {
    this.pinhole = pinhole;
    declareVectors(pinhole.width, pinhole.height);
    // computing the 3D ray through each pixel in the pinhole camera at it's canonical
    // location
    PinholePtoN_F64 pixelToNormalized = new PinholePtoN_F64();
    pixelToNormalized.set(pinhole.fx, pinhole.fy, pinhole.skew, pinhole.cx, pinhole.cy);
    Point2D_F64 norm = new Point2D_F64();
    for (int pixelY = 0; pixelY < pinhole.height; pixelY++) {
        for (int pixelX = 0; pixelX < pinhole.width; pixelX++) {
            pixelToNormalized.compute(pixelX, pixelY, norm);
            Point3D_F64 v = vectors[pixelY * pinhole.width + pixelX];
            v.set(norm.x, norm.y, 1);
        }
    }
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) PinholePtoN_F64(boofcv.alg.distort.pinhole.PinholePtoN_F64) Point2D_F64(georegression.struct.point.Point2D_F64)

Example 5 with PinholePtoN_F64

use of boofcv.alg.distort.pinhole.PinholePtoN_F64 in project BoofCV by lessthanoptimal.

the class ImplRectifyImageOps_F64 method transformPixelToRectNorm.

public static Point2Transform2_F64 transformPixelToRectNorm(CameraPinholeRadial param, DMatrixRMaj rectify, DMatrixRMaj rectifyK) {
    if (rectifyK.get(0, 1) != 0)
        throw new IllegalArgumentException("Skew should be zero in rectified images");
    Point2Transform2_F64 remove_p_to_p = narrow(param).undistort_F64(true, true);
    PointTransformHomography_F64 rectifyDistort = new PointTransformHomography_F64(rectify);
    PinholePtoN_F64 pixelToNorm = new PinholePtoN_F64();
    pixelToNorm.set(rectifyK.get(0, 0), rectifyK.get(1, 1), rectifyK.get(0, 1), rectifyK.get(0, 2), rectifyK.get(1, 2));
    return new SequencePoint2Transform2_F64(remove_p_to_p, rectifyDistort, pixelToNorm);
}
Also used : PinholePtoN_F64(boofcv.alg.distort.pinhole.PinholePtoN_F64) PointTransformHomography_F64(boofcv.alg.distort.PointTransformHomography_F64) SequencePoint2Transform2_F64(boofcv.struct.distort.SequencePoint2Transform2_F64) Point2Transform2_F64(boofcv.struct.distort.Point2Transform2_F64) SequencePoint2Transform2_F64(boofcv.struct.distort.SequencePoint2Transform2_F64)

Aggregations

PinholePtoN_F64 (boofcv.alg.distort.pinhole.PinholePtoN_F64)5 Point2D_F64 (georegression.struct.point.Point2D_F64)3 PointTransformHomography_F64 (boofcv.alg.distort.PointTransformHomography_F64)2 Point2Transform2_F64 (boofcv.struct.distort.Point2Transform2_F64)2 SequencePoint2Transform2_F64 (boofcv.struct.distort.SequencePoint2Transform2_F64)2 AssociatedTriple (boofcv.struct.geo.AssociatedTriple)1 Point3D_F64 (georegression.struct.point.Point3D_F64)1 VerbosePrint (org.ddogleg.struct.VerbosePrint)1