use of georegression.struct.line.LineSegment2D_F32 in project BoofCV by lessthanoptimal.
the class TestConnectLinesGrid method checkHalfCircleAngle.
/**
* Orientation of two lines should be compared using the half circle angle.
*
* The test is designed to test that both angles are computed using atan() and compared
* between 0 and 180 degrees
*/
@Test
public void checkHalfCircleAngle() {
MatrixOfList<LineSegment2D_F32> grid = new MatrixOfList<>(1, 1);
grid.get(0, 0).add(new LineSegment2D_F32(0, 0, 0, 2));
grid.get(0, 0).add(new LineSegment2D_F32(0, 0, 0.001f, -2));
ConnectLinesGrid app = new ConnectLinesGrid(0.1, 1, 1);
app.process(grid);
List<LineSegment2D_F32> list = grid.createSingleList();
assertEquals(1, list.size());
}
use of georegression.struct.line.LineSegment2D_F32 in project BoofCV by lessthanoptimal.
the class TestConnectLinesGrid method checkTangentTolerance.
/**
* Makes sure the tangent distance tolerance parameter is correctly set and processed
*/
@Test
public void checkTangentTolerance() {
MatrixOfList<LineSegment2D_F32> grid = new MatrixOfList<>(1, 1);
grid.get(0, 0).add(new LineSegment2D_F32(0, 0, 2, 0));
grid.get(0, 0).add(new LineSegment2D_F32(2, 1, 4, 1));
// have the tolerance be too tight
ConnectLinesGrid app = new ConnectLinesGrid(2, 0.1, 2);
app.process(grid);
assertEquals(2, grid.createSingleList().size());
// now make the tolerance broader
app = new ConnectLinesGrid(2, 1.1, 2);
app.process(grid);
assertEquals(1, grid.createSingleList().size());
}
use of georegression.struct.line.LineSegment2D_F32 in project BoofCV by lessthanoptimal.
the class TestConnectLinesGrid method connectInSameRegion.
/**
* Very basic check which sees if lines are being connected in the same region
*/
@Test
public void connectInSameRegion() {
MatrixOfList<LineSegment2D_F32> grid = new MatrixOfList<>(1, 1);
grid.get(0, 0).add(new LineSegment2D_F32(0, 0, 2, 3));
grid.get(0, 0).add(new LineSegment2D_F32(2, 3, 4, 6));
ConnectLinesGrid app = new ConnectLinesGrid(0.1, 1, 1);
app.process(grid);
List<LineSegment2D_F32> list = grid.createSingleList();
assertEquals(1, list.size());
LineSegment2D_F32 l = list.get(0);
assertEquals(0, l.a.x, 1e-8);
assertEquals(0, l.a.y, 1e-8);
assertEquals(4, l.b.x, 1e-8);
assertEquals(6, l.b.y, 1e-8);
}
use of georegression.struct.line.LineSegment2D_F32 in project BoofCV by lessthanoptimal.
the class ExampleLineDetection method detectLineSegments.
/**
* Detects segments inside the image
*
* @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 detectLineSegments(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
DetectLineSegmentsGridRansac<T, D> detector = FactoryDetectLineAlgs.lineRansac(40, 30, 2.36, true, imageType, derivType);
List<LineSegment2D_F32> found = detector.detect(input);
// display the results
ImageLinePanel gui = new ImageLinePanel();
gui.setBackground(image);
gui.setLineSegments(found);
gui.setPreferredSize(new Dimension(image.getWidth(), image.getHeight()));
listPanel.addItem(gui, "Found Line Segments");
}
use of georegression.struct.line.LineSegment2D_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;
}
Aggregations