Search in sources :

Example 1 with Corner

use of boofcv.alg.shapes.polyline.splitmerge.PolylineSplitMerge.Corner in project BoofCV by lessthanoptimal.

the class TestPolylineSplitMerge method computePotentialSplitScore.

@Test
public void computePotentialSplitScore() {
    PolylineSplitMerge alg = new PolylineSplitMerge();
    alg.setMinimumSideLength(5);
    alg.setThresholdSideSplitScore(0);
    List<Point2D_I32> contour = new ArrayList<>();
    for (int i = 0; i < 20; i++) {
        contour.add(new Point2D_I32(i, 0));
    }
    // add some texture
    contour.get(3).y = 5;
    contour.get(15).y = 5;
    // this will be selected as the corner since it's the farthest away
    contour.get(10).y = 20;
    alg.addCorner(0);
    alg.addCorner(19);
    Element<Corner> e = alg.list.getHead();
    e.object.sideError = 20;
    alg.computePotentialSplitScore(contour, e, false);
    assertTrue(e.object.splitable);
    assertTrue(e.object.splitError0 > 0);
    assertTrue(e.object.splitError1 > 0);
    assertEquals(10, e.object.splitLocation);
}
Also used : Corner(boofcv.alg.shapes.polyline.splitmerge.PolylineSplitMerge.Corner) ArrayList(java.util.ArrayList) Point2D_I32(georegression.struct.point.Point2D_I32) Test(org.junit.Test)

Example 2 with Corner

use of boofcv.alg.shapes.polyline.splitmerge.PolylineSplitMerge.Corner in project BoofCV by lessthanoptimal.

the class TestPolylineSplitMerge method next.

@Test
public void next() {
    PolylineSplitMerge alg = new PolylineSplitMerge();
    Corner a = alg.corners.grow();
    Corner b = alg.corners.grow();
    Corner c = alg.corners.grow();
    alg.list.pushTail(a);
    alg.list.pushTail(b);
    alg.list.pushTail(c);
    assertTrue(c == alg.next(alg.list.find(b)).object);
    assertTrue(a == alg.next(alg.list.find(c)).object);
}
Also used : Corner(boofcv.alg.shapes.polyline.splitmerge.PolylineSplitMerge.Corner) Test(org.junit.Test)

Example 3 with Corner

use of boofcv.alg.shapes.polyline.splitmerge.PolylineSplitMerge.Corner in project BoofCV by lessthanoptimal.

the class TestPolylineSplitMerge method canBeSplit.

@Test
public void canBeSplit() {
    PolylineSplitMerge alg = new PolylineSplitMerge();
    // only the contour's size matters
    List<Point2D_I32> contour = new ArrayList<>();
    for (int i = 0; i < 50; i++) {
        contour.add(new Point2D_I32());
    }
    for (int i = 0; i < 10; i++) {
        Corner c = alg.corners.grow();
        c.index = i * 5;
        // give it an error greater than zero so that it will pass the side test
        c.sideError = 0.1;
        alg.list.pushTail(c);
    }
    alg.setMinimumSideLength(4);
    // turn off this test
    alg.setThresholdSideSplitScore(0);
    assertTrue(alg.canBeSplit(contour, alg.list.getElement(5, true), false));
    assertTrue(alg.canBeSplit(contour, alg.list.getElement(9, true), false));
    alg.setMinimumSideLength(5);
    assertFalse(alg.canBeSplit(contour, alg.list.getElement(5, true), false));
    assertFalse(alg.canBeSplit(contour, alg.list.getElement(9, true), false));
    // test side split score
    alg.setMinimumSideLength(4);
    alg.setThresholdSideSplitScore(1);
    alg.list.getElement(5, true).object.sideError = 1.0000001;
    assertTrue(alg.canBeSplit(contour, alg.list.getElement(5, true), false));
    alg.list.getElement(5, true).object.sideError = 0.9999999;
    assertFalse(alg.canBeSplit(contour, alg.list.getElement(5, true), false));
    // test the must split flag
    alg.list.getElement(5, true).object.sideError = 0.9999999;
    assertTrue(alg.canBeSplit(contour, alg.list.getElement(5, true), true));
    alg.setMinimumSideLength(6);
    assertFalse(alg.canBeSplit(contour, alg.list.getElement(5, true), true));
    // Will it try to split a side with zero error if the min score is zero?
    alg.setMinimumSideLength(4);
    alg.setThresholdSideSplitScore(0);
    alg.corners.get(0).sideError = 0;
    assertFalse(alg.canBeSplit(contour, alg.list.getHead(), false));
    // now the minimum length is 1 and the side isn't perfect. Still shouldn't split
    // because the length is now 1
    alg.setMinimumSideLength(1);
    alg.corners.get(0).sideError = 0.1;
    alg.corners.get(0).index = 0;
    alg.corners.get(1).index = 1;
    assertFalse(alg.canBeSplit(contour, alg.list.getHead(), false));
}
Also used : Corner(boofcv.alg.shapes.polyline.splitmerge.PolylineSplitMerge.Corner) ArrayList(java.util.ArrayList) Point2D_I32(georegression.struct.point.Point2D_I32) Test(org.junit.Test)

Example 4 with Corner

use of boofcv.alg.shapes.polyline.splitmerge.PolylineSplitMerge.Corner in project BoofCV by lessthanoptimal.

the class TestPolylineSplitMerge method previous.

@Test
public void previous() {
    PolylineSplitMerge alg = new PolylineSplitMerge();
    Corner a = alg.corners.grow();
    Corner b = alg.corners.grow();
    Corner c = alg.corners.grow();
    alg.list.pushTail(a);
    alg.list.pushTail(b);
    alg.list.pushTail(c);
    assertTrue(a == alg.previous(alg.list.find(b)).object);
    assertTrue(c == alg.previous(alg.list.find(a)).object);
}
Also used : Corner(boofcv.alg.shapes.polyline.splitmerge.PolylineSplitMerge.Corner) Test(org.junit.Test)

Example 5 with Corner

use of boofcv.alg.shapes.polyline.splitmerge.PolylineSplitMerge.Corner in project BoofCV by lessthanoptimal.

the class TestPolylineSplitMerge method findInitialTriangle.

/**
 * Give it an obvious triangle and see if it finds it
 */
@Test
public void findInitialTriangle() {
    List<Point2D_I32> contour = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        contour.add(new Point2D_I32(i, i));
    }
    for (int i = 0; i < 10; i++) {
        contour.add(new Point2D_I32(9 - i, 9));
    }
    for (int i = 0; i < 8; i++) {
        contour.add(new Point2D_I32(0, 8 - i));
    }
    PolylineSplitMerge alg = new PolylineSplitMerge();
    assertTrue(alg.findInitialTriangle(contour));
    assertEquals(3, alg.list.size());
    // the order was specially selected knowing what the current algorithm is
    // te indexes are what it should be no matter what
    Element<Corner> e = alg.list.getHead();
    assertEquals(9, e.object.index);
    e = e.next;
    assertEquals(19, e.object.index);
    e = e.next;
    assertEquals(0, e.object.index);
}
Also used : Corner(boofcv.alg.shapes.polyline.splitmerge.PolylineSplitMerge.Corner) ArrayList(java.util.ArrayList) Point2D_I32(georegression.struct.point.Point2D_I32) Test(org.junit.Test)

Aggregations

Corner (boofcv.alg.shapes.polyline.splitmerge.PolylineSplitMerge.Corner)5 Test (org.junit.Test)5 Point2D_I32 (georegression.struct.point.Point2D_I32)3 ArrayList (java.util.ArrayList)3