Search in sources :

Example 6 with RectangleLength2D_F64

use of georegression.struct.shapes.RectangleLength2D_F64 in project BoofCV by lessthanoptimal.

the class DistortImageOps method boundBox_F64.

/**
 * Finds an axis-aligned bounding box which would contain a image after it has been transformed.
 * The returned bounding box can be larger then the original image.
 *
 * @param srcWidth Width of the source image
 * @param srcHeight Height of the source image
 * @param transform Transform being applied to the image
 * @return Bounding box
 */
public static RectangleLength2D_F64 boundBox_F64(int srcWidth, int srcHeight, PixelTransform2_F64 transform) {
    ImageRectangle_F64 r = new ImageRectangle_F64();
    r.x0 = r.y0 = Double.MAX_VALUE;
    r.x1 = r.y1 = -Double.MAX_VALUE;
    for (int y = 0; y < srcHeight; y++) {
        transform.compute(0, y);
        updateBoundBox(transform, r);
        transform.compute(srcWidth, y);
        updateBoundBox(transform, r);
    }
    for (int x = 0; x < srcWidth; x++) {
        transform.compute(x, 0);
        updateBoundBox(transform, r);
        transform.compute(x, srcHeight);
        updateBoundBox(transform, r);
    }
    return new RectangleLength2D_F64(r.x0, r.y0, r.x1 - r.x0, r.y1 - r.y0);
}
Also used : ImageRectangle_F64(boofcv.struct.ImageRectangle_F64) RectangleLength2D_F64(georegression.struct.shapes.RectangleLength2D_F64)

Example 7 with RectangleLength2D_F64

use of georegression.struct.shapes.RectangleLength2D_F64 in project BoofCV by lessthanoptimal.

the class TestDistortImageOps method boundBox_F64.

@Test
public void boundBox_F64() {
    // basic sanity check
    Affine2D_F64 affine = new Affine2D_F64(1, 0, 0, 1, 2, 3);
    PixelTransformAffine_F64 transform = new PixelTransformAffine_F64(affine);
    RectangleLength2D_F64 found = DistortImageOps.boundBox_F64(10, 20, transform);
    assertEquals(2, found.x0, 1e-8);
    assertEquals(3, found.y0, 1e-8);
    assertEquals(10, found.width, 1e-8);
    assertEquals(20, found.height, 1e-8);
}
Also used : Affine2D_F64(georegression.struct.affine.Affine2D_F64) RectangleLength2D_F64(georegression.struct.shapes.RectangleLength2D_F64) Test(org.junit.Test)

Aggregations

RectangleLength2D_F64 (georegression.struct.shapes.RectangleLength2D_F64)7 PointToPixelTransform_F64 (boofcv.alg.distort.PointToPixelTransform_F64)4 Point2Transform2_F64 (boofcv.struct.distort.Point2Transform2_F64)3 SequencePoint2Transform2_F64 (boofcv.struct.distort.SequencePoint2Transform2_F64)3 PointTransformHomography_F64 (boofcv.alg.distort.PointTransformHomography_F64)2 CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)2 Affine2D_F64 (georegression.struct.affine.Affine2D_F64)2 Test (org.junit.Test)2 ImageRectangle_F64 (boofcv.struct.ImageRectangle_F64)1