Search in sources :

Example 1 with LineGeneral2D_F64

use of georegression.struct.line.LineGeneral2D_F64 in project BoofCV by lessthanoptimal.

the class RefinePolygonToContour method process.

/**
 * Refines the estimate using all the points in the contour
 *
 * @param contour (Input) The shape's contour
 * @param vertexes (Input) List of indexes that are vertexes in the contour
 * @param output (Output) Storage for where the found polygon is saved to
 */
public void process(List<Point2D_I32> contour, GrowQueue_I32 vertexes, Polygon2D_F64 output) {
    int numDecreasing = 0;
    for (int i = vertexes.size - 1, j = 0; j < vertexes.size; i = j, j++) {
        if (vertexes.get(i) > vertexes.get(j))
            numDecreasing++;
    }
    boolean decreasing = numDecreasing > 1;
    output.vertexes.resize(vertexes.size);
    lines.resize(vertexes.size);
    // fit lines to each size
    for (int i = vertexes.size - 1, j = 0; j < vertexes.size; i = j, j++) {
        int idx0 = vertexes.get(i);
        int idx1 = vertexes.get(j);
        if (decreasing) {
            int tmp = idx0;
            idx0 = idx1;
            idx1 = tmp;
        }
        if (idx0 > idx1) {
            // handle special case where it wraps around
            work.clear();
            for (int k = idx0; k < contour.size(); k++) {
                work.add(contour.get(k));
            }
            for (int k = 0; k < idx1; k++) {
                work.add(contour.get(k));
            }
            FitLine_I32.polar(work, 0, work.size(), polar);
        } else {
            FitLine_I32.polar(contour, idx0, idx1 - idx0, polar);
        }
        UtilLine2D_F64.convert(polar, lines.get(i));
    }
    // find the corners by intersecting the side
    for (int i = vertexes.size - 1, j = 0; j < vertexes.size; i = j, j++) {
        LineGeneral2D_F64 lineA = lines.get(i);
        LineGeneral2D_F64 lineB = lines.get(j);
        Intersection2D_F64.intersection(lineA, lineB, output.get(j));
    }
}
Also used : LineGeneral2D_F64(georegression.struct.line.LineGeneral2D_F64)

Example 2 with LineGeneral2D_F64

use of georegression.struct.line.LineGeneral2D_F64 in project BoofCV by lessthanoptimal.

the class FitLinesToContour method fitLinesUsingCorners.

/**
 * Fits lines across the sequence of corners
 *
 * @param numLines number of lines it will fit
 */
boolean fitLinesUsingCorners(int numLines, GrowQueue_I32 cornerIndexes) {
    for (int i = 1; i <= numLines; i++) {
        int index0 = cornerIndexes.get(CircularIndex.addOffset(anchor0, i - 1, cornerIndexes.size));
        int index1 = cornerIndexes.get(CircularIndex.addOffset(anchor0, i, cornerIndexes.size));
        if (index0 == index1)
            return false;
        if (!fitLine(index0, index1, lines.get(i - 1))) {
            // TODO do something more intelligent here.  Just leave the corners as is?
            return false;
        }
        LineGeneral2D_F64 l = lines.get(i - 1);
        if (Double.isNaN(l.A) || Double.isNaN(l.B) || Double.isNaN(l.C)) {
            throw new RuntimeException("This should be impossible");
        }
    }
    return true;
}
Also used : LineGeneral2D_F64(georegression.struct.line.LineGeneral2D_F64)

Example 3 with LineGeneral2D_F64

use of georegression.struct.line.LineGeneral2D_F64 in project BoofCV by lessthanoptimal.

the class TestRefinePolygonToGrayLine method optimize_line_perfect.

public void optimize_line_perfect(boolean black, Class imageType) {
    renderDistortedRectangles(black, imageType);
    RefinePolygonToGrayLine alg = createAlg(4, imageType);
    Quadrilateral_F64 input = new Quadrilateral_F64(x0, y0, x0, y1, x1, y1, x1, y0);
    LineGeneral2D_F64 found = new LineGeneral2D_F64();
    alg.setImage(image);
    assertTrue(alg.optimize(input.a, input.b, found));
    assertTrue(Distance2D_F64.distance(found, input.a) <= 1e-4);
    assertTrue(Distance2D_F64.distance(found, input.b) <= 1e-4);
}
Also used : LineGeneral2D_F64(georegression.struct.line.LineGeneral2D_F64) Quadrilateral_F64(georegression.struct.shapes.Quadrilateral_F64)

Example 4 with LineGeneral2D_F64

use of georegression.struct.line.LineGeneral2D_F64 in project BoofCV by lessthanoptimal.

the class TestUtilShapePolygon method convert.

@Test
public void convert() {
    Polygon2D_F64 orig = new Polygon2D_F64(10, 20, 30, 21, 19.5, -10, 8, -8);
    LineGeneral2D_F64[] lines = new LineGeneral2D_F64[4];
    lines[0] = UtilLine2D_F64.convert(orig.getLine(0, null), (LineGeneral2D_F64) null);
    lines[1] = UtilLine2D_F64.convert(orig.getLine(1, null), (LineGeneral2D_F64) null);
    lines[2] = UtilLine2D_F64.convert(orig.getLine(2, null), (LineGeneral2D_F64) null);
    lines[3] = UtilLine2D_F64.convert(orig.getLine(3, null), (LineGeneral2D_F64) null);
    Polygon2D_F64 found = new Polygon2D_F64(4);
    assertTrue(UtilShapePolygon.convert(lines, found));
    assertTrue(orig.isIdentical(found, 1e-8));
}
Also used : LineGeneral2D_F64(georegression.struct.line.LineGeneral2D_F64) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) Test(org.junit.Test)

Example 5 with LineGeneral2D_F64

use of georegression.struct.line.LineGeneral2D_F64 in project BoofCV by lessthanoptimal.

the class TestFitLinesToContour method fitLinesUsingCorners.

@Test
public void fitLinesUsingCorners() {
    FitLinesToContour alg = new FitLinesToContour();
    alg.contour = createSquare(10, 12, 30, 40);
    GrowQueue_I32 corners = createSquareCorners(10, 12, 30, 40);
    alg.lines.resize(3);
    alg.anchor0 = 1;
    alg.fitLinesUsingCorners(3, corners);
    LineGeneral2D_F64 expected = new LineGeneral2D_F64();
    for (int i = 0; i < 3; i++) {
        alg.fitLine(corners.get((i + 1) % 4), corners.get((i + 2) % 4), expected);
        LineGeneral2D_F64 found = alg.lines.get(i);
        assertEquals(expected.A, found.A, 1e-8);
        assertEquals(expected.B, found.B, 1e-8);
        assertEquals(expected.C, found.C, 1e-8);
    }
}
Also used : LineGeneral2D_F64(georegression.struct.line.LineGeneral2D_F64) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32) Test(org.junit.Test)

Aggregations

LineGeneral2D_F64 (georegression.struct.line.LineGeneral2D_F64)12 Test (org.junit.Test)5 LineSegment2D_F64 (georegression.struct.line.LineSegment2D_F64)3 Point2D_I32 (georegression.struct.point.Point2D_I32)3 Point2D_F64 (georegression.struct.point.Point2D_F64)2 Polygon2D_F64 (georegression.struct.shapes.Polygon2D_F64)2 GrowQueue_I32 (org.ddogleg.struct.GrowQueue_I32)2 ClosestPoint2D_F64 (georegression.metric.ClosestPoint2D_F64)1 LineParametric2D_F64 (georegression.struct.line.LineParametric2D_F64)1 Vector2D_F64 (georegression.struct.point.Vector2D_F64)1 Quadrilateral_F64 (georegression.struct.shapes.Quadrilateral_F64)1 ArrayList (java.util.ArrayList)1