use of georegression.struct.line.LineParametric2D_F32 in project BoofCV by lessthanoptimal.
the class LineImageOps method pruneSimilarLines.
/**
* Prunes similar looking lines, but keeps the lines with the most intensity.
*
* @param lines
* @param intensity
* @param toleranceAngle
* @return
*/
public static List<LineParametric2D_F32> pruneSimilarLines(List<LineParametric2D_F32> lines, float[] intensity, float toleranceAngle, float toleranceDist, int imgWidth, int imgHeight) {
int[] indexSort = new int[intensity.length];
QuickSort_F32 sort = new QuickSort_F32();
sort.sort(intensity, 0, lines.size(), indexSort);
float[] theta = new float[lines.size()];
List<LineSegment2D_F32> segments = new ArrayList<>(lines.size());
for (int i = 0; i < lines.size(); i++) {
LineParametric2D_F32 l = lines.get(i);
theta[i] = UtilAngle.atanSafe(l.getSlopeY(), l.getSlopeX());
segments.add(convert(l, imgWidth, imgHeight));
}
for (int i = segments.size() - 1; i >= 0; i--) {
LineSegment2D_F32 a = segments.get(indexSort[i]);
if (a == null)
continue;
for (int j = i - 1; j >= 0; j--) {
LineSegment2D_F32 b = segments.get(indexSort[j]);
if (b == null)
continue;
if (UtilAngle.distHalf(theta[indexSort[i]], theta[indexSort[j]]) > toleranceAngle)
continue;
Point2D_F32 p = Intersection2D_F32.intersection(a, b, null);
if (p != null && p.x >= 0 && p.y >= 0 && p.x < imgWidth && p.y < imgHeight) {
segments.set(indexSort[j], null);
} else {
float distA = Distance2D_F32.distance(a, b.a);
float distB = Distance2D_F32.distance(a, b.b);
if (distA <= toleranceDist || distB < toleranceDist) {
segments.set(indexSort[j], null);
}
}
}
}
List<LineParametric2D_F32> ret = new ArrayList<>();
for (int i = 0; i < segments.size(); i++) {
if (segments.get(i) != null) {
ret.add(lines.get(i));
}
}
return ret;
}
use of georegression.struct.line.LineParametric2D_F32 in project BoofCV by lessthanoptimal.
the class LineImageOps method pruneRelativeIntensity.
public static List<LineParametric2D_F32> pruneRelativeIntensity(List<LineParametric2D_F32> lines, float[] intensity, float fraction) {
int[] indexSort = new int[intensity.length];
QuickSort_F32 sort = new QuickSort_F32();
sort.sort(intensity, 0, lines.size(), indexSort);
float threshold = intensity[indexSort[lines.size() - 1]] * fraction;
List<LineParametric2D_F32> ret = new ArrayList<>();
for (int i = 0; i < lines.size(); i++) {
if (intensity[i] >= threshold) {
ret.add(lines.get(i));
}
}
return ret;
}
use of georegression.struct.line.LineParametric2D_F32 in project BoofCV by lessthanoptimal.
the class GeneralDetectLineTests method obviousLine.
private <T extends ImageGray<T>> void obviousLine(Class<T> imageType) {
T input = GeneralizedImageOps.createSingleBand(imageType, width, height);
GImageMiscOps.fillRectangle(input, 30, 0, 0, lineLocation, height);
DetectLine<T> alg = createAlg(imageType);
List<LineParametric2D_F32> found = alg.detect(input);
assertTrue(found.size() >= 1);
// see if at least one of the lines is within tolerance
boolean foundMatch = false;
for (LineParametric2D_F32 l : found) {
Point2D_F32 p = l.getPoint();
double angle = l.getAngle();
if (Math.abs(p.x - lineLocation) < toleranceLocation && ((UtilAngle.dist(Math.PI / 2, angle) <= toleranceAngle) || (UtilAngle.dist(-Math.PI / 2, angle) <= toleranceAngle))) {
foundMatch = true;
break;
}
}
assertTrue(foundMatch);
}
use of georegression.struct.line.LineParametric2D_F32 in project BoofCV by lessthanoptimal.
the class ExampleLineDetection method detectLines.
/**
* Detects lines inside the image using different types of Hough detectors
*
* @param image Input image.
* @param imageType Type of image processed by line detector.
* @param derivType Type of image derivative.
*/
public static <T extends ImageGray<T>, D extends ImageGray<D>> void detectLines(BufferedImage image, Class<T> imageType, Class<D> derivType) {
// convert the line into a single band image
T input = ConvertBufferedImage.convertFromSingle(image, null, imageType);
// Comment/uncomment to try a different type of line detector
DetectLineHoughPolar<T, D> detector = FactoryDetectLineAlgs.houghPolar(new ConfigHoughPolar(3, 30, 2, Math.PI / 180, edgeThreshold, maxLines), imageType, derivType);
// DetectLineHoughFoot<T,D> detector = FactoryDetectLineAlgs.houghFoot(
// new ConfigHoughFoot(3, 8, 5, edgeThreshold,maxLines), imageType, derivType);
// DetectLineHoughFootSubimage<T,D> detector = FactoryDetectLineAlgs.houghFootSub(
// new ConfigHoughFootSubimage(3, 8, 5, edgeThreshold,maxLines, 2, 2), imageType, derivType);
List<LineParametric2D_F32> found = detector.detect(input);
// display the results
ImageLinePanel gui = new ImageLinePanel();
gui.setBackground(image);
gui.setLines(found);
gui.setPreferredSize(new Dimension(image.getWidth(), image.getHeight()));
listPanel.addItem(gui, "Found Lines");
}
use of georegression.struct.line.LineParametric2D_F32 in project BoofCV by lessthanoptimal.
the class TestHoughTransformLinePolar method obviousLines.
/**
* See if it can detect an obvious line in the image
*/
@Test
public void obviousLines() {
GrayU8 image = new GrayU8(width, height);
for (int i = 0; i < height; i++) {
image.set(5, i, 1);
}
NonMaxSuppression extractor = FactoryFeatureExtractor.nonmax(new ConfigExtract(4, 5, 0, true));
HoughTransformLinePolar alg = new HoughTransformLinePolar(extractor, 40, 180);
alg.transform(image);
FastQueue<LineParametric2D_F32> lines = alg.extractLines();
assertTrue(lines.size() > 0);
for (int i = 0; i < lines.size(); i++) {
LineParametric2D_F32 l = lines.get(i);
assertEquals(l.p.x, 5, 0.1);
assertEquals(Math.abs(l.slope.x), 0, 1e-4);
assertEquals(Math.abs(l.slope.y), 1, 0.1);
}
}
Aggregations