Search in sources :

Example 66 with Point2D_I32

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

the class TestSegmentMeanShiftSearchColor method simpleTest.

/**
 * Process a random image and do a basic sanity check on the output
 */
@Test
public void simpleTest() {
    Planar<GrayF32> image = new Planar<>(GrayF32.class, 20, 25, 2);
    GImageMiscOps.fillUniform(image, rand, 0, 256);
    SegmentMeanShiftSearchColor<Planar<GrayF32>> alg = new SegmentMeanShiftSearchColor<>(30, 0.05f, interp, 2, 2, 200, false, imageType);
    alg.process(image);
    FastQueue<Point2D_I32> locations = alg.getModeLocation();
    GrowQueue_I32 counts = alg.getRegionMemberCount();
    GrayS32 peaks = alg.getPixelToRegion();
    FastQueue<float[]> values = alg.getModeColor();
    // there should be a fair number of local peaks due to the image being random
    assertTrue(locations.size > 20);
    // all the lists should be the same size
    assertEquals(locations.size, counts.size);
    assertEquals(locations.size, values.size);
    // total members should equal the number of pixels
    int totalMembers = 0;
    for (int i = 0; i < counts.size; i++) {
        totalMembers += counts.get(i);
    }
    assertEquals(20 * 25, totalMembers);
    // see if the peak to index image is set up correctly and that all the peaks make sense
    for (int y = 0; y < peaks.height; y++) {
        for (int x = 0; x < peaks.width; x++) {
            int peak = peaks.get(x, y);
            // can't test the value because its floating point location which is interpolated using the kernel
            // and the location is lost
            // assertEquals(x+" "+y,computeValue(peakX,peakY,image),value,50);
            assertTrue(counts.get(peak) > 0);
        }
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) Planar(boofcv.struct.image.Planar) Point2D_I32(georegression.struct.point.Point2D_I32) GrayS32(boofcv.struct.image.GrayS32) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32) Test(org.junit.Test)

Example 67 with Point2D_I32

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

the class TestShapeFittingOps method createRectangle_I32.

public static List<Point2D_I32> createRectangle_I32(int width, int height, int numPoints) {
    List<Point2D_I32> points = new ArrayList<>();
    int length = width * 2 + height * 2 - 4;
    for (int i = 0; i < numPoints; i++) {
        int x = i * length / numPoints;
        if (x < width) {
            points.add(new Point2D_I32(x, 0));
        } else if (x < width + height - 2) {
            int y = x - width + 1;
            points.add(new Point2D_I32(width - 1, y));
        } else if (x < width * 2 + height - 2) {
            int xx = x - width - height + 3;
            points.add(new Point2D_I32(width - xx, height - 1));
        } else {
            int y = x - width * 2 - height + 4;
            points.add(new Point2D_I32(0, height - y));
        }
    }
    return points;
}
Also used : ArrayList(java.util.ArrayList) Point2D_I32(georegression.struct.point.Point2D_I32)

Example 68 with Point2D_I32

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

the class TestSplitMergeLineFitSegment method checkZeroOne.

/**
 * Tests contours with zero and one points in them
 */
@Test
public void checkZeroOne() {
    List<Point2D_I32> contour = new ArrayList<>();
    SplitMergeLineFitSegment alg = new SplitMergeLineFitSegment(0.15, MIN_SPLIT, 100);
    alg.process(contour, splits);
    assertEquals(0, splits.size);
    contour.add(new Point2D_I32(2, 3));
    alg.process(contour, splits);
    assertEquals(0, splits.size);
}
Also used : ArrayList(java.util.ArrayList) Point2D_I32(georegression.struct.point.Point2D_I32) Test(org.junit.Test)

Example 69 with Point2D_I32

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

the class TestPackedSetsPoint2D_I32 method writeOverSet_badsize.

@Test
public void writeOverSet_badsize() {
    PackedSetsPoint2D_I32 alg = new PackedSetsPoint2D_I32(6);
    alg.grow();
    for (int i = 0; i < 12; i++) {
        alg.addPointToTail(1, i);
    }
    List<Point2D_I32> expected = new ArrayList<>();
    for (int i = 0; i < 20; i++) {
        expected.add(new Point2D_I32(3, i));
    }
    try {
        alg.writeOverSet(0, expected);
        fail("exception expected");
    } catch (RuntimeException ignore) {
    }
}
Also used : ArrayList(java.util.ArrayList) Point2D_I32(georegression.struct.point.Point2D_I32) Test(org.junit.Test)

Example 70 with Point2D_I32

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

the class TestImageBase method indexToPixel.

@Test
public void indexToPixel() {
    Dummy a = new Dummy();
    a.startIndex = 7;
    a.stride = 5;
    a.width = 4;
    a.height = 11;
    Point2D_I32 p = a.indexToPixel(7 + 6 * 5 + 2);
    assertEquals(2, p.x);
    assertEquals(6, p.y);
}
Also used : Point2D_I32(georegression.struct.point.Point2D_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