Search in sources :

Example 61 with Point2D_I32

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

the class TestBinaryEllipseDetectorPixel method undistortContour_WithDistortion.

/**
 * Undistort the image when distortion model is provided
 */
@Test
public void undistortContour_WithDistortion() {
    List<Point2D_I32> input = new ArrayList<>();
    FastQueue<Point2D_F64> output = new FastQueue<>(Point2D_F64.class, true);
    for (int i = 0; i < 10; i++) {
        input.add(new Point2D_I32(i, i));
    }
    BinaryEllipseDetectorPixel alg = new BinaryEllipseDetectorPixel();
    alg.setLensDistortion(new PixelTransformAffine_F32(new Affine2D_F32(1, 0, 0, 1, 10.0f, 0)));
    alg.undistortContour(input, output);
    assertEquals(input.size(), output.size);
    for (int i = 0; i < input.size(); i++) {
        Point2D_I32 p = input.get(i);
        assertEquals(p.x + 10, output.get(i).x, 1e-8);
        assertEquals(p.y, output.get(i).y, 1e-8);
    }
}
Also used : Point2D_F64(georegression.struct.point.Point2D_F64) Affine2D_F32(georegression.struct.affine.Affine2D_F32) FastQueue(org.ddogleg.struct.FastQueue) ArrayList(java.util.ArrayList) Point2D_I32(georegression.struct.point.Point2D_I32) PixelTransformAffine_F32(boofcv.alg.distort.PixelTransformAffine_F32) Test(org.junit.Test)

Example 62 with Point2D_I32

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

the class TestContourEdgeIntensity method smallContours.

@Test
public void smallContours() {
    GrayU8 image = new GrayU8(200, 150);
    RectangleLength2D_I32 r = new RectangleLength2D_I32(20, 25, 5, 4);
    ImageMiscOps.fillRectangle(image, 200, r.x0, r.y0, r.width, r.height);
    List<Point2D_I32> contour = rectToContour(r);
    ContourEdgeIntensity<GrayU8> alg = new ContourEdgeIntensity<>(30, 2, 1.0, GrayU8.class);
    alg.setImage(image);
    alg.process(contour, true);
    assertTrue(alg.getOutsideAverage() < 8);
    assertTrue(alg.getInsideAverage() > 195);
}
Also used : RectangleLength2D_I32(georegression.struct.shapes.RectangleLength2D_I32) Point2D_I32(georegression.struct.point.Point2D_I32) GrayU8(boofcv.struct.image.GrayU8) Test(org.junit.Test)

Example 63 with Point2D_I32

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

the class TestContourEdgeIntensity method rectToContour.

public static List<Point2D_I32> rectToContour(RectangleLength2D_I32 r) {
    List<Point2D_I32> contour = new ArrayList<>();
    int x1 = r.x0 + r.width - 1;
    int y1 = r.y0 + r.height - 1;
    for (int i = 1; i < r.width; i++) {
        contour.add(new Point2D_I32(r.x0 + i, r.y0));
    }
    for (int i = 1; i < r.height; i++) {
        contour.add(new Point2D_I32(x1, r.y0 + i));
    }
    for (int i = 1; i < r.width; i++) {
        contour.add(new Point2D_I32(x1 - i, y1));
    }
    for (int i = 1; i < r.height; i++) {
        contour.add(new Point2D_I32(r.x0, y1 - i));
    }
    return contour;
}
Also used : ArrayList(java.util.ArrayList) Point2D_I32(georegression.struct.point.Point2D_I32)

Example 64 with Point2D_I32

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

the class TestContourEdgeIntensity method simpleCase.

@Test
public void simpleCase() {
    GrayU8 image = new GrayU8(200, 150);
    RectangleLength2D_I32 r = new RectangleLength2D_I32(20, 25, 30, 35);
    ImageMiscOps.fillRectangle(image, 200, r.x0, r.y0, r.width, r.height);
    List<Point2D_I32> contour = rectToContour(r);
    ContourEdgeIntensity<GrayU8> alg = new ContourEdgeIntensity<>(20, 2, 1.0, GrayU8.class);
    alg.setImage(image);
    alg.process(contour, true);
    assertTrue(alg.getOutsideAverage() < 8);
    assertTrue(alg.getInsideAverage() > 195);
    // test the CCW flag AND multiple calls
    alg.process(contour, false);
    assertTrue(alg.getOutsideAverage() > 195);
    assertTrue(alg.getInsideAverage() < 8);
    // change the number of contour samples
    alg = new ContourEdgeIntensity<>(10, 2, 1.0, GrayU8.class);
    alg.setImage(image);
    alg.process(contour, true);
    assertTrue(alg.getOutsideAverage() < 8);
    assertTrue(alg.getInsideAverage() > 195);
    // change the number of tangent samples
    alg = new ContourEdgeIntensity<>(20, 1, 1.0, GrayU8.class);
    alg.setImage(image);
    alg.process(contour, true);
    assertTrue(alg.getOutsideAverage() < 8);
    assertTrue(alg.getInsideAverage() > 195);
}
Also used : RectangleLength2D_I32(georegression.struct.shapes.RectangleLength2D_I32) Point2D_I32(georegression.struct.point.Point2D_I32) GrayU8(boofcv.struct.image.GrayU8) Test(org.junit.Test)

Example 65 with Point2D_I32

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

the class TestMergeRegionMeanShift method basicAll.

@Test
public void basicAll() {
    MergeRegionMeanShift alg = new MergeRegionMeanShift(1, 1);
    GrayS32 pixelToRegion = new GrayS32(4, 4);
    pixelToRegion.data = new int[] { 0, 0, 0, 1, 2, 0, 0, 1, 2, 0, 1, 1, 0, 0, 3, 1 };
    GrowQueue_I32 regionMemberCount = new GrowQueue_I32();
    regionMemberCount.data = new int[] { 1, 2, 3, 4 };
    regionMemberCount.size = 4;
    FastQueue<float[]> regionColor = createList(5, 1, 6, 4);
    FastQueue<Point2D_I32> modeLocation = new FastQueue<>(Point2D_I32.class, true);
    modeLocation.grow().set(0, 0);
    modeLocation.grow().set(3, 3);
    modeLocation.grow().set(0, 1);
    modeLocation.grow().set(2, 3);
    alg.process(pixelToRegion, regionMemberCount, regionColor, modeLocation);
    GrayS32 expectedP2R = new GrayS32(4, 4);
    expectedP2R.data = new int[] { 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 2, 1 };
    int[] expectedCount = new int[] { 4, 2, 4 };
    for (int i = 0; i < expectedP2R.data.length; i++) assertEquals(expectedP2R.data[i], pixelToRegion.data[i]);
    for (int i = 0; i < expectedCount.length; i++) assertEquals(expectedCount[i], regionMemberCount.data[i]);
}
Also used : FastQueue(org.ddogleg.struct.FastQueue) Point2D_I32(georegression.struct.point.Point2D_I32) GrayS32(boofcv.struct.image.GrayS32) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32) Test(org.junit.Test)

Aggregations

Point2D_I32 (georegression.struct.point.Point2D_I32)153 Test (org.junit.Test)64 ArrayList (java.util.ArrayList)41 GrowQueue_I32 (org.ddogleg.struct.GrowQueue_I32)21 Point2D_F64 (georegression.struct.point.Point2D_F64)11 EdgeContour (boofcv.alg.feature.detect.edge.EdgeContour)8 GrayF32 (boofcv.struct.image.GrayF32)8 GrayS32 (boofcv.struct.image.GrayS32)7 Contour (boofcv.alg.filter.binary.Contour)6 TupleDesc_F64 (boofcv.struct.feature.TupleDesc_F64)6 GrayU8 (boofcv.struct.image.GrayU8)6 PackedSetsPoint2D_I32 (boofcv.struct.PackedSetsPoint2D_I32)5 RectangleLength2D_I32 (georegression.struct.shapes.RectangleLength2D_I32)5 UtilPoint2D_I32 (georegression.geometry.UtilPoint2D_I32)4 Polygon2D_F64 (georegression.struct.shapes.Polygon2D_F64)4 EdgeSegment (boofcv.alg.feature.detect.edge.EdgeSegment)3 Corner (boofcv.alg.shapes.polyline.splitmerge.PolylineSplitMerge.Corner)3 FactoryDescribeImageDense (boofcv.factory.feature.dense.FactoryDescribeImageDense)3 PointIndex_I32 (boofcv.struct.PointIndex_I32)3 LineGeneral2D_F64 (georegression.struct.line.LineGeneral2D_F64)3