use of georegression.struct.line.LineParametric2D_F32 in project BoofCV by lessthanoptimal.
the class HoughTransformLinePolar method extractLines.
/**
* Searches for local maximas and converts into lines.
*
* @return Found lines in the image.
*/
public FastQueue<LineParametric2D_F32> extractLines() {
lines.reset();
foundLines.reset();
foundIntensity.reset();
extractor.process(transform, null, null, null, foundLines);
int w2 = transform.width / 2;
for (int i = 0; i < foundLines.size(); i++) {
Point2D_I16 p = foundLines.get(i);
float r = (float) (r_max * (p.x - w2) / w2);
float c = tableTrig.c[p.y];
float s = tableTrig.s[p.y];
float x0 = r * c + originX;
float y0 = r * s + originY;
foundIntensity.push(transform.get(p.x, p.y));
LineParametric2D_F32 l = lines.grow();
l.p.set(x0, y0);
l.slope.set(-s, c);
Point2D_F64 p2 = new Point2D_F64();
lineToCoordinate(l, p2);
}
return lines;
}
use of georegression.struct.line.LineParametric2D_F32 in project BoofCV by lessthanoptimal.
the class ImageLinePruneMerge method pruneSimilar.
public void pruneSimilar(float toleranceAngle, float toleranceDist, int imgWidth, int imgHeight) {
sortByIntensity();
float[] theta = new float[lines.size()];
List<LineSegment2D_F32> segments = new ArrayList<>(lines.size());
for (int i = 0; i < lines.size(); i++) {
Data d = lines.get(i);
LineParametric2D_F32 l = d.line;
theta[i] = UtilAngle.atanSafe(l.getSlopeY(), l.getSlopeX());
segments.add(LineImageOps.convert(l, imgWidth, imgHeight));
}
for (int i = 0; i < segments.size(); i++) {
LineSegment2D_F32 a = segments.get(i);
if (a == null)
continue;
for (int j = i + 1; j < segments.size(); j++) {
LineSegment2D_F32 b = segments.get(j);
if (b == null)
continue;
// see if they are nearly parallel
if (UtilAngle.distHalf(theta[i], theta[j]) > toleranceAngle)
continue;
Point2D_F32 p = Intersection2D_F32.intersection(a, b, null);
// see if it is nearly parallel and intersects inside the image
if (p != null && p.x >= 0 && p.y >= 0 && p.x < imgWidth && p.y < imgHeight) {
segments.set(j, null);
} else {
// now just see if they are very close
float distA = Distance2D_F32.distance(a, b.a);
float distB = Distance2D_F32.distance(a, b.b);
if (distA <= toleranceDist || distB < toleranceDist) {
segments.set(j, null);
}
}
}
}
List<Data> filtered = new ArrayList<>();
for (int i = 0; i < segments.size(); i++) {
if (segments.get(i) != null) {
filtered.add(lines.get(i));
}
}
lines = filtered;
}
use of georegression.struct.line.LineParametric2D_F32 in project BoofCV by lessthanoptimal.
the class LineImageOps method mergeIntoA.
private static void mergeIntoA(LineSegment2D_F32 a, LineSegment2D_F32 b) {
LineParametric2D_F32 paraA = UtilLine2D_F32.convert(a, (LineParametric2D_F32) null);
Point2D_F32[] pts = new Point2D_F32[4];
float[] t = new float[4];
pts[0] = a.a;
pts[1] = a.b;
pts[2] = b.a;
pts[3] = b.b;
for (int i = 0; i < 4; i++) t[i] = ClosestPoint2D_F32.closestPointT(paraA, pts[i]);
float min = t[0];
float max = min;
int indexMin = 0;
int indexMax = 0;
for (int i = 1; i < 4; i++) {
float v = t[i];
if (v < min) {
min = v;
indexMin = i;
}
if (v > max) {
max = v;
indexMax = i;
}
}
// set the first line to the extreme points on each line
a.a.set(pts[indexMin]);
a.b.set(pts[indexMax]);
}
use of georegression.struct.line.LineParametric2D_F32 in project BoofCV by lessthanoptimal.
the class TestHoughTransformLineFootOfNorm method obviousLines.
private <D extends ImageGray<D>> void obviousLines(Class<D> derivType) {
GrayU8 binary = new GrayU8(width, height);
D derivX = GeneralizedImageOps.createSingleBand(derivType, width, height);
D derivY = GeneralizedImageOps.createSingleBand(derivType, width, height);
for (int i = 0; i < height; i++) {
binary.set(5, i, 1);
GeneralizedImageOps.set(derivX, 5, i, 20);
}
NonMaxSuppression extractor = FactoryFeatureExtractor.nonmax(new ConfigExtract(4, 2, 0, true));
HoughTransformLineFootOfNorm alg = new HoughTransformLineFootOfNorm(extractor, 2);
alg.transform(derivX, derivY, binary);
FastQueue<LineParametric2D_F32> lines = alg.extractLines();
assertEquals(1, lines.size());
LineParametric2D_F32 l = lines.get(0);
assertEquals(l.p.x, 5, 0.1);
// normalize the line for easier evaluation
l.slope.x /= l.slope.norm();
l.slope.y /= l.slope.norm();
assertEquals(0, Math.abs(l.slope.x), 0);
assertEquals(1, Math.abs(l.slope.y), 0.1);
}
use of georegression.struct.line.LineParametric2D_F32 in project BoofCV by lessthanoptimal.
the class HoughTransformLineFootOfNorm method extractLines.
/**
* Searches for local maximas and converts into lines.
*
* @return Found lines in the image.
*/
public FastQueue<LineParametric2D_F32> extractLines() {
lines.reset();
foundLines.reset();
foundIntensity.reset();
extractor.process(transform, null, candidates, null, foundLines);
for (int i = 0; i < foundLines.size(); i++) {
Point2D_I16 p = foundLines.get(i);
int x0 = p.x - originX;
int y0 = p.y - originY;
if (Math.abs(x0) >= minDistanceFromOrigin || Math.abs(y0) >= minDistanceFromOrigin) {
LineParametric2D_F32 l = lines.grow();
l.p.set(p.x, p.y);
l.slope.set(-y0, x0);
foundIntensity.push(transform.get(p.x, p.y));
}
}
return lines;
}
Aggregations