Search in sources :

Example 76 with Point2D_I32

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

the class ChecksGenericPointsToPolyline method checkMaxVertexes_loop.

/**
 * Checks to see if this feature can be changed and is enforced
 */
@Test
public void checkMaxVertexes_loop() {
    PointsToPolyline alg = createAlg(true);
    alg.setMaximumSides(3);
    List<Point2D_I32> contour = TestPolylineSplitMerge.rect(0, 0, 10, 20);
    GrowQueue_I32 found = new GrowQueue_I32();
    // will fail because the error is too large for 3 sides
    assertFalse(alg.process(contour, found));
    alg.setMaximumSides(4);
    assertTrue(alg.process(contour, found));
    check(found, 0, 10, 30, 40);
}
Also used : Point2D_I32(georegression.struct.point.Point2D_I32) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32) Test(org.junit.Test)

Example 77 with Point2D_I32

use of georegression.struct.point.Point2D_I32 in project narchy by automenta.

the class ShapeSensor method drawPolygon.

public static <T extends Point2D_I32> void drawPolygon(List<T> vertexes, boolean loop, Graphics2D g2) {
    for (int i = 0; i < vertexes.size() - 1; i++) {
        Point2D_I32 p0 = vertexes.get(i);
        Point2D_I32 p1 = vertexes.get(i + 1);
        g2.drawLine(p0.x, p0.y, p1.x, p1.y);
    }
    if (loop && !vertexes.isEmpty()) {
        Point2D_I32 p0 = vertexes.get(0);
        Point2D_I32 p1 = vertexes.get(vertexes.size() - 1);
        g2.drawLine(p0.x, p0.y, p1.x, p1.y);
    }
}
Also used : Point2D_I32(georegression.struct.point.Point2D_I32)

Example 78 with Point2D_I32

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

the class DescribePointBriefSO method process.

public void process(float c_x, float c_y, float orientation, float radius, TupleDesc_B feature) {
    float scale = (float) (radius / BoofDefaults.BRIEF_SCALE_TO_RADIUS);
    // NOTE: This doesn't seem to take in account the interpolation border.  Might not work algs
    // other than bilinear interpolation
    boolean isInside = BoofMiscOps.checkInside(blur, c_x, c_y, definition.radius * scale);
    float c = (float) Math.cos(orientation);
    float s = (float) Math.sin(orientation);
    Arrays.fill(feature.data, 0);
    if (isInside) {
        for (int i = 0; i < definition.samplePoints.length; i++) {
            Point2D_I32 a = definition.samplePoints[i];
            // rotate the points
            float x0 = c_x + (c * a.x - s * a.y) * scale;
            float y0 = c_y + (s * a.x + c * a.y) * scale;
            values[i] = interp.get_fast(x0, y0);
        }
    } else {
        // handle the image border case
        for (int i = 0; i < definition.samplePoints.length; i++) {
            Point2D_I32 a = definition.samplePoints[i];
            // rotate the points
            float x0 = c_x + (c * a.x - s * a.y) * scale;
            float y0 = c_y + (s * a.x + c * a.y) * scale;
            if (BoofMiscOps.checkInside(blur, x0, y0)) {
                // it might be inside the image but too close to the border for unsafe
                values[i] = interp.get(x0, y0);
            }
        }
    }
    for (int i = 0; i < definition.compare.length; i++) {
        Point2D_I32 comp = definition.compare[i];
        if (values[comp.x] < values[comp.y]) {
            feature.data[i / 32] |= 1 << (i % 32);
        }
    }
}
Also used : Point2D_I32(georegression.struct.point.Point2D_I32)

Example 79 with Point2D_I32

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

the class HysteresisEdgeTracePoints method trace.

/**
 * Traces along object's contour starting at the specified seed.  As it does so it will set the intensity of
 * points which are below the lower threshold to zero and add points to contour.
 *
 * @param x x-coordinate of seed pixel above threshold
 * @param y y-coordinate of seed pixel above threshold
 * @param indexInten Pixel index in the image array of coordinate (x,y)
 */
protected void trace(int x, int y, int indexInten) {
    e = new EdgeContour();
    contours.add(e);
    int dx, dy;
    addFirstSegment(x, y);
    intensity.data[indexInten] = MARK_TRAVERSED;
    while (open.size() > 0) {
        EdgeSegment s = open.remove(open.size() - 1);
        Point2D_I32 p = s.points.get(0);
        indexInten = intensity.getIndex(p.x, p.y);
        int indexDir = direction.getIndex(p.x, p.y);
        boolean first = true;
        while (true) {
            // ----- First check along the direction of the edge.  Only need to check 2 points this way
            switch(direction.data[indexDir]) {
                case 0:
                    dx = 0;
                    dy = 1;
                    break;
                case 1:
                    dx = 1;
                    dy = -1;
                    break;
                case 2:
                    dx = 1;
                    dy = 0;
                    break;
                case -1:
                    dx = 1;
                    dy = 1;
                    break;
                default:
                    throw new RuntimeException("Unknown direction: " + direction.data[indexDir]);
            }
            int indexForward = indexInten + dy * intensity.stride + dx;
            int indexBackward = indexInten - dy * intensity.stride - dx;
            int prevIndexDir = indexDir;
            boolean match = false;
            // pixel coordinate of forward and backward point
            x = p.x;
            y = p.y;
            int fx = p.x + dx, fy = p.y + dy;
            int bx = p.x - dx, by = p.y - dy;
            // See if the forward point is in bounds and above the lower threshold
            if (intensity.isInBounds(fx, fy) && intensity.data[indexForward] >= lower) {
                intensity.data[indexForward] = MARK_TRAVERSED;
                p = queuePoints.grow();
                p.set(fx, fy);
                s.points.add(p);
                // note that a match has already been found
                match = true;
                indexInten = indexForward;
                indexDir = prevIndexDir + dy * intensity.stride + dx;
            }
            // See if the backwards point is in bounds and above the lower threshold
            if (intensity.isInBounds(bx, by) && intensity.data[indexBackward] >= lower) {
                intensity.data[indexBackward] = MARK_TRAVERSED;
                if (match) {
                    // a match was found in the forwards direction, so start a new segment here
                    startNewSegment(bx, by, s);
                } else {
                    p = queuePoints.grow();
                    p.set(bx, by);
                    s.points.add(p);
                    match = true;
                    indexInten = indexBackward;
                    indexDir = prevIndexDir - dy * intensity.stride - dx;
                }
            }
            // search the whole 8-neighborhood.
            if (first || !match) {
                boolean priorMatch = match;
                // Check local neighbors if its one of the end points, which would be the first point or
                // any point for which no matches were found
                match = checkAllNeighbors(x, y, s, match);
                if (!match)
                    break;
                else {
                    // if it was the first it's no longer the first
                    first = false;
                    // the point at the end was just added and is to be searched in the next iteration
                    if (!priorMatch) {
                        p = s.points.get(s.points.size() - 1);
                        indexInten = intensity.getIndex(p.x, p.y);
                        indexDir = direction.getIndex(p.x, p.y);
                    }
                }
            }
        }
    }
}
Also used : Point2D_I32(georegression.struct.point.Point2D_I32)

Example 80 with Point2D_I32

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

the class HysteresisEdgeTracePoints method startNewSegment.

/**
 * Starts a new segment in the contour at the specified coordinate.
 */
private void startNewSegment(int x, int y, EdgeSegment parent) {
    // create the point which is the first
    Point2D_I32 p = queuePoints.grow();
    p.set(x, y);
    EdgeSegment s = new EdgeSegment();
    s.parent = parent.index;
    // if a new segment is created that means an extra point has been added to the end already, hence -2 and not -1
    s.parentPixel = parent.points.size() - 2;
    s.index = e.segments.size();
    s.points.add(p);
    e.segments.add(s);
    open.add(s);
}
Also used : Point2D_I32(georegression.struct.point.Point2D_I32)

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