Search in sources :

Example 51 with Point2D_F32

use of georegression.struct.point.Point2D_F32 in project BoofCV by lessthanoptimal.

the class LineImageOps method convert.

/**
 * Find the point in which the line intersects the image border and create a line segment at those points
 */
public static LineSegment2D_F32 convert(LineParametric2D_F32 l, int width, int height) {
    double t0 = (0 - l.p.x) / l.getSlopeX();
    double t1 = (0 - l.p.y) / l.getSlopeY();
    double t2 = (width - l.p.x) / l.getSlopeX();
    double t3 = (height - l.p.y) / l.getSlopeY();
    Point2D_F32 a = computePoint(l, t0);
    Point2D_F32 b = computePoint(l, t1);
    Point2D_F32 c = computePoint(l, t2);
    Point2D_F32 d = computePoint(l, t3);
    List<Point2D_F32> inside = new ArrayList<>();
    checkAddInside(width, height, a, inside);
    checkAddInside(width, height, b, inside);
    checkAddInside(width, height, c, inside);
    checkAddInside(width, height, d, inside);
    if (inside.size() != 2) {
        return null;
    // System.out.println("interesting");
    }
    return new LineSegment2D_F32(inside.get(0), inside.get(1));
}
Also used : LineSegment2D_F32(georegression.struct.line.LineSegment2D_F32) ArrayList(java.util.ArrayList) Point2D_F32(georegression.struct.point.Point2D_F32) ClosestPoint2D_F32(georegression.metric.ClosestPoint2D_F32)

Example 52 with Point2D_F32

use of georegression.struct.point.Point2D_F32 in project BoofCV by lessthanoptimal.

the class GenericBackgroundModelMovingChecks method checkSegmented.

/**
 * Checks to see if pixels outside of BG are marked as unknown
 */
private void checkSegmented(Homography2D_F32 transform, GrayU8 segmented, double tol) {
    Point2D_F32 p = new Point2D_F32();
    int numErrors = 0;
    for (int y = 0; y < segmented.height; y++) {
        for (int x = 0; x < segmented.width; x++) {
            HomographyPointOps_F32.transform(transform, x, y, p);
            int xx = (int) Math.floor(p.x);
            int yy = (int) Math.floor(p.y);
            if (segmented.isInBounds(xx, yy)) {
                if (segmented.get(x, y) == 2)
                    numErrors++;
            } else {
                if (segmented.get(x, y) != 2)
                    numErrors++;
            }
        }
    }
    assertTrue(numErrors / (double) (segmented.width * segmented.height) <= tol);
}
Also used : Point2D_F32(georegression.struct.point.Point2D_F32)

Example 53 with Point2D_F32

use of georegression.struct.point.Point2D_F32 in project BoofCV by lessthanoptimal.

the class MultiCameraToEquirectangular method addCamera.

/**
 * Adds a camera and attempts to compute the mask from the provided distortion model.  if a pixel is rendered
 * outside the bounds in the input image then it is masked out.  If the forwards/backwards transform is too
 * different then it is masked out.
 *
 * @param cameraToCommon Rigid body transform from this camera to the common frame the equirectangular image
 *                       is in
 * @param factory Distortion model
 * @param camMask Binary mask with invalid pixels marked as not zero.  Pixels are in camera image frame.
 */
public void addCamera(Se3_F32 cameraToCommon, LensDistortionWideFOV factory, GrayU8 camMask) {
    Point2Transform3_F32 p2s = factory.undistortPtoS_F32();
    Point3Transform2_F32 s2p = factory.distortStoP_F32();
    EquiToCamera equiToCamera = new EquiToCamera(cameraToCommon.getR(), s2p);
    GrayF32 equiMask = new GrayF32(equiWidth, equHeight);
    PixelTransformCached_F32 transformEquiToCam = new PixelTransformCached_F32(equiWidth, equHeight, new PointToPixelTransform_F32(equiToCamera));
    int width = camMask.width;
    int height = camMask.height;
    Point3D_F32 p3b = new Point3D_F32();
    Point2D_F32 p2 = new Point2D_F32();
    for (int row = 0; row < equHeight; row++) {
        for (int col = 0; col < equiWidth; col++) {
            equiToCamera.compute(col, row, p2);
            if (UtilEjml.isUncountable(p2.x) || UtilEjml.isUncountable(p2.y)) {
                // can't have it be an invalid number in the cache, but had to be invalid so that the mask
                // could be set to zero.  So set it to some valid value that won't cause it to blow up
                transformEquiToCam.getPixel(col, row).set(-1, -1);
                continue;
            }
            int camX = (int) (p2.x + 0.5f);
            int camY = (int) (p2.y + 0.5f);
            if (camX < 0 || camY < 0 || camX >= width || camY >= height)
                continue;
            if (camMask.unsafe_get(camX, camY) == 1) {
                p2s.compute(p2.x, p2.y, p3b);
                if (Double.isNaN(p3b.x) || Double.isNaN(p3b.y) || Double.isNaN(p3b.z))
                    continue;
                double angle = UtilVector3D_F32.acute(equiToCamera.unitCam, p3b);
                if (angle < maskToleranceAngle) {
                    equiMask.set(col, row, 1);
                }
            }
        }
    }
    cameras.add(new Camera(equiMask, transformEquiToCam));
}
Also used : Point3D_F32(georegression.struct.point.Point3D_F32) GrayF32(boofcv.struct.image.GrayF32) PointToPixelTransform_F32(boofcv.alg.distort.PointToPixelTransform_F32) Point2D_F32(georegression.struct.point.Point2D_F32) Point2Transform3_F32(boofcv.struct.distort.Point2Transform3_F32) Point3Transform2_F32(boofcv.struct.distort.Point3Transform2_F32) PixelTransformCached_F32(boofcv.alg.distort.PixelTransformCached_F32)

Example 54 with Point2D_F32

use of georegression.struct.point.Point2D_F32 in project BoofCV by lessthanoptimal.

the class PointDeform_MLS method setSource.

@Override
public void setSource(List<Point2D_F32> locations) {
    alg.reset();
    for (int i = 0; i < locations.size(); i++) {
        Point2D_F32 p = locations.get(i);
        alg.addControl(p.x, p.y);
    }
    alg.fixateUndistorted();
}
Also used : Point2D_F32(georegression.struct.point.Point2D_F32)

Example 55 with Point2D_F32

use of georegression.struct.point.Point2D_F32 in project BoofCV by lessthanoptimal.

the class ChecksPointDeformKeyPoints method individualDstSameAsAll.

/**
 * Makes sure modifying a single points is the same as modifying all the points at once
 */
@Test
public void individualDstSameAsAll() {
    List<Point2D_F32> src = createTestPoints();
    List<Point2D_F32> dst = createTestPoints();
    PointDeformKeyPoints alg = createAlgorithm();
    alg.setImageShape(80, 100);
    alg.setSource(src);
    alg.setSource(dst);
    alg.setDestination(1, 20, 25);
    Point2D_F32 expected = new Point2D_F32();
    alg.compute(12, 19.5f, expected);
    dst.get(1).set(20, 25);
    Point2D_F32 found = new Point2D_F32();
    alg.compute(12, 19.5f, found);
    assertEquals(expected.x, found.x, GrlConstants.TEST_F32);
    assertEquals(expected.y, found.y, GrlConstants.TEST_F32);
}
Also used : Point2D_F32(georegression.struct.point.Point2D_F32) Test(org.junit.Test)

Aggregations

Point2D_F32 (georegression.struct.point.Point2D_F32)98 Test (org.junit.Test)36 Point3D_F32 (georegression.struct.point.Point3D_F32)10 Point2Transform2_F32 (boofcv.struct.distort.Point2Transform2_F32)9 LineSegment2D_F32 (georegression.struct.line.LineSegment2D_F32)8 ArrayList (java.util.ArrayList)8 Point2D_F64 (georegression.struct.point.Point2D_F64)7 FMatrixRMaj (org.ejml.data.FMatrixRMaj)7 CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)5 LineParametric2D_F32 (georegression.struct.line.LineParametric2D_F32)5 Point2Transform3_F32 (boofcv.struct.distort.Point2Transform3_F32)4 Point3Transform2_F32 (boofcv.struct.distort.Point3Transform2_F32)4 GrayF32 (boofcv.struct.image.GrayF32)4 ClosestPoint2D_F32 (georegression.metric.ClosestPoint2D_F32)4 PointToPixelTransform_F32 (boofcv.alg.distort.PointToPixelTransform_F32)3 CameraPinhole (boofcv.struct.calib.CameraPinhole)3 GrayU8 (boofcv.struct.image.GrayU8)3 PixelTransformCached_F32 (boofcv.alg.distort.PixelTransformCached_F32)2 PinholePtoN_F32 (boofcv.alg.distort.pinhole.PinholePtoN_F32)2 CalibrationObservation (boofcv.alg.geo.calibration.CalibrationObservation)2