Search in sources :

Example 1 with Rectangle2D_I32

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

the class BenchmarkSpeckleFilter method renderImage.

/**
 * This is intended to crudely simulate a disparity image. In a disparity images there are large patches with
 * speckle noise that should be one region. The difference is speed between the two methods is about what
 * is seen in real world cases. When it was mostly random the naive method was slightly faster.
 */
private void renderImage(Random rand, ImageGray<?> image) {
    image.reshape(size, size);
    Rectangle2D_I32 rect = new Rectangle2D_I32();
    for (int i = 0; i < 20; i++) {
        rect.x0 = rand.nextInt(size - 40);
        rect.y0 = rand.nextInt(size - 40);
        rect.x1 = rect.x0 + 40 + rand.nextInt(size / 2);
        rect.y1 = rect.y0 + 40 + rand.nextInt(size / 2);
        rect.x1 = Math.min(rect.x1, size);
        rect.y1 = Math.min(rect.y1, size);
        double color = rand.nextDouble() * fillColor;
        GImageMiscOps.fillRectangle(image, color, rect.x0, rect.y0, rect.getWidth(), rect.getHeight());
    }
    GImageMiscOps.addGaussian(image, rand, 0.7, 0, 255);
    for (int i = 0; i < 1000; i++) {
        GeneralizedImageOps.set(image, rand.nextInt(size), rand.nextInt(size), fillColor);
    }
}
Also used : Rectangle2D_I32(georegression.struct.shapes.Rectangle2D_I32)

Example 2 with Rectangle2D_I32

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

the class CommonFitPolygonChecks method findMatchesOriginal.

/**
 * Compare found rectangle against rectangles in the original undistorted image
 */
protected int findMatchesOriginal(Polygon2D_F64 found, double tol) {
    int match = 0;
    for (int i = 0; i < rectangles.size(); i++) {
        Rectangle2D_I32 ri = rectangles.get(i);
        Rectangle2D_F64 r = new Rectangle2D_F64(ri.x0, ri.y0, ri.x1, ri.y1);
        Polygon2D_F64 p = new Polygon2D_F64(4);
        UtilPolygons2D_F64.convert(r, p);
        if (p.isCCW())
            p.flip();
        if (UtilPolygons2D_F64.isEquivalent(found, p, tol))
            match++;
    }
    return match;
}
Also used : Rectangle2D_F64(georegression.struct.shapes.Rectangle2D_F64) Rectangle2D_I32(georegression.struct.shapes.Rectangle2D_I32) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64)

Example 3 with Rectangle2D_I32

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

the class CommonFitPolygonChecks method renderDistortedRectangles.

public void renderDistortedRectangles(boolean blackShape, Class imageType) {
    orig = GeneralizedImageOps.createSingleBand(imageType, width, height);
    image = GeneralizedImageOps.createSingleBand(imageType, width, height);
    int white = blackShape ? this.white : this.black;
    int black = blackShape ? this.black : this.white;
    GImageMiscOps.fill(orig, white);
    GImageMiscOps.fill(image, white);
    distorted.clear();
    for (Rectangle2D_I32 q : rectangles) {
        if (fittingToBinaryImage)
            GImageMiscOps.fillRectangle(orig, black, q.x0, q.y0, q.x1 - q.x0 + 1, q.y1 - q.y0 + 1);
        else
            GImageMiscOps.fillRectangle(orig, black, q.x0, q.y0, q.x1 - q.x0, q.y1 - q.y0);
        Polygon2D_F64 tran = new Polygon2D_F64(4);
        AffinePointOps_F64.transform(transform, q.x0, q.y0, tran.get(0));
        AffinePointOps_F64.transform(transform, q.x0, q.y1, tran.get(1));
        AffinePointOps_F64.transform(transform, q.x1, q.y1, tran.get(2));
        AffinePointOps_F64.transform(transform, q.x1, q.y0, tran.get(3));
        distorted.add(tran);
    }
    new FDistort(orig, image).border(white).affine(transform).apply();
    if (showRendered) {
        ListDisplayPanel panel = new ListDisplayPanel();
        panel.addImage(orig, "Original");
        panel.addImage(image, "Image");
        ShowImages.showWindow(panel, "Rendered");
        try {
            Thread.sleep(4000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
Also used : ListDisplayPanel(boofcv.gui.ListDisplayPanel) FDistort(boofcv.abst.distort.FDistort) Rectangle2D_I32(georegression.struct.shapes.Rectangle2D_I32) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64)

Example 4 with Rectangle2D_I32

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

the class TestDetectPolygonFromContour method easyTestNoDistortion.

@Test
void easyTestNoDistortion() {
    rectangles.add(new Rectangle2D_I32(30, 30, 60, 60));
    rectangles.add(new Rectangle2D_I32(90, 30, 120, 60));
    rectangles.add(new Rectangle2D_I32(30, 90, 60, 120));
    rectangles.add(new Rectangle2D_I32(90, 90, 120, 120));
    for (Class imageType : imageTypes) {
        // the match should be perfect since the size of the
        checkDetected(imageType, 0.01);
    }
}
Also used : Rectangle2D_I32(georegression.struct.shapes.Rectangle2D_I32) Test(org.junit.jupiter.api.Test)

Example 5 with Rectangle2D_I32

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

the class TestDetectPolygonFromContour method someAffineDistortion.

@Test
void someAffineDistortion() {
    rectangles.add(new Rectangle2D_I32(30, 30, 60, 60));
    rectangles.add(new Rectangle2D_I32(90, 30, 120, 60));
    rectangles.add(new Rectangle2D_I32(30, 90, 60, 120));
    rectangles.add(new Rectangle2D_I32(90, 90, 120, 120));
    transform.setTo(1.1, 0.2, 0.12, 1.3, 10.2, 20.3);
    for (Class imageType : imageTypes) {
        checkDetected(imageType, 1.0);
    }
}
Also used : Rectangle2D_I32(georegression.struct.shapes.Rectangle2D_I32) Test(org.junit.jupiter.api.Test)

Aggregations

Rectangle2D_I32 (georegression.struct.shapes.Rectangle2D_I32)21 Test (org.junit.jupiter.api.Test)17 Polygon2D_F64 (georegression.struct.shapes.Polygon2D_F64)6 Affine2D_F64 (georegression.struct.affine.Affine2D_F64)3 Rectangle2D_F64 (georegression.struct.shapes.Rectangle2D_F64)3 Se2_F64 (georegression.struct.se.Se2_F64)2 FDistort (boofcv.abst.distort.FDistort)1 ListDisplayPanel (boofcv.gui.ListDisplayPanel)1 PointIndex_I32 (boofcv.struct.PointIndex_I32)1 Polygon2D_I32 (georegression.struct.shapes.Polygon2D_I32)1 Term (nars.term.Term)1