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);
}
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);
}
}
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);
}
}
}
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);
}
}
}
}
}
}
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);
}
Aggregations