use of georegression.struct.point.Point2D_I32 in project BoofCV by lessthanoptimal.
the class ContourEdgeIntensity method process.
public void process(List<Point2D_I32> contour, boolean isCCW) {
if (imageWidth == 0)
throw new RuntimeException("You didn't call setImage()");
// How many pixels along the contour it will step between samples
int step;
if (contour.size() <= contourSamples)
step = 1;
else
step = contour.size() / contourSamples;
// Want the local tangent. How many contour points forward it will sample to get the tangent
int sample = Math.max(1, Math.min(step / 2, 5));
edgeOutside = edgeInside = 0;
int totalInside = 0;
int totalOutside = 0;
// traverse the contour
for (int i = 0; i < contour.size(); i += step) {
Point2D_I32 a = contour.get(i);
Point2D_I32 b = contour.get((i + sample) % contour.size());
// compute the tangent using the two points
float dx = b.x - a.x, dy = b.y - a.y;
float r = (float) Math.sqrt(dx * dx + dy * dy);
dx /= r;
dy /= r;
// sample points tangent to the contour but not the contour itself
for (int j = 0; j < tangentSamples; j++) {
float x, y;
float length = (j + 1) * tangentStep;
x = a.x + length * dy;
y = a.y - length * dx;
if (x >= 0 && y >= 0 && x <= imageWidth - 1 && y <= imageHeight - 1) {
edgeOutside += sampler.get(x, y);
totalOutside++;
}
x = a.x - length * dy;
y = a.y + length * dx;
if (x >= 0 && y >= 0 && x <= imageWidth - 1 && y <= imageHeight - 1) {
edgeInside += sampler.get(x, y);
totalInside++;
}
}
}
edgeOutside /= totalOutside;
edgeInside /= totalInside;
if (!isCCW) {
float tmp = edgeOutside;
edgeOutside = edgeInside;
edgeInside = tmp;
}
}
use of georegression.struct.point.Point2D_I32 in project BoofCV by lessthanoptimal.
the class DetectPolygonFromContour method touchesBorder.
/**
* Checks to see if some part of the contour touches the image border. Most likely cropped
*/
protected final boolean touchesBorder(List<Point2D_I32> contour) {
int endX = labeled.width - 1;
int endY = labeled.height - 1;
for (int j = 0; j < contour.size(); j++) {
Point2D_I32 p = contour.get(j);
if (p.x == 0 || p.y == 0 || p.x == endX || p.y == endY) {
return true;
}
}
return false;
}
use of georegression.struct.point.Point2D_I32 in project BoofCV by lessthanoptimal.
the class MinimizeEnergyPrune method computeSegmentEnergy.
/**
* Computes the energy for a segment defined by the two corner indexes
*/
protected double computeSegmentEnergy(GrowQueue_I32 corners, int cornerA, int cornerB) {
int indexA = corners.get(cornerA);
int indexB = corners.get(cornerB);
if (indexA == indexB) {
return 100000.0;
}
Point2D_I32 a = contour.get(indexA);
Point2D_I32 b = contour.get(indexB);
line.p.x = a.x;
line.p.y = a.y;
line.slope.set(b.x - a.x, b.y - a.y);
double total = 0;
int length = circularDistance(indexA, indexB);
for (int k = 1; k < length; k++) {
Point2D_I32 c = getContour(indexA + 1 + k);
point.set(c.x, c.y);
total += Distance2D_F64.distanceSq(line, point);
}
return (total + splitPenalty) / a.distance2(b);
}
use of georegression.struct.point.Point2D_I32 in project BoofCV by lessthanoptimal.
the class RefinePolyLineCorner method createLine.
/**
* Given segment information create a line in general notation which has been normalized
*/
private void createLine(int index0, int index1, List<Point2D_I32> contour, LineGeneral2D_F64 line) {
if (index1 < 0)
System.out.println("SHIT");
Point2D_I32 p0 = contour.get(index0);
Point2D_I32 p1 = contour.get(index1);
// System.out.println("createLine "+p0+" "+p1);
work.a.set(p0.x, p0.y);
work.b.set(p1.x, p1.y);
UtilLine2D_F64.convert(work, line);
// ensure A*A + B*B = 1
line.normalize();
}
use of georegression.struct.point.Point2D_I32 in project BoofCV by lessthanoptimal.
the class MaximumLineDistance method selectSplitPoint.
@Override
public void selectSplitPoint(List<Point2D_I32> contour, int indexA, int indexB, PolylineSplitMerge.SplitResults results) {
PolylineSplitMerge.assignLine(contour, indexA, indexB, line);
if (indexB >= indexA) {
results.index = indexA;
results.score = -1;
for (int i = indexA + 1; i < indexB; i++) {
Point2D_I32 p = contour.get(i);
double distanceSq = Distance2D_F64.distanceSq(line, p.x, p.y);
if (distanceSq > results.score) {
results.score = distanceSq;
results.index = i;
}
}
} else {
results.index = indexA;
results.score = -1;
int distance = contour.size() - indexA + indexB;
for (int i = 1; i < distance; i++) {
int index = (indexA + i) % contour.size();
Point2D_I32 p = contour.get(index);
double distanceSq = Distance2D_F64.distanceSq(line, p.x, p.y);
if (distanceSq > results.score) {
results.score = distanceSq;
results.index = index;
}
}
}
// if( results.index >= contour.size() )
// throw new RuntimeException("Egads");
}
Aggregations