use of georegression.struct.line.LineSegment2D_F32 in project BoofCV by lessthanoptimal.
the class LineImageOps method pruneSmall.
public static void pruneSmall(List<LineSegment2D_F32> lines, float threshold) {
threshold *= threshold;
Iterator<LineSegment2D_F32> iter = lines.iterator();
while (iter.hasNext()) {
LineSegment2D_F32 l = iter.next();
if (l.getLength2() <= threshold) {
iter.remove();
}
}
}
use of georegression.struct.line.LineSegment2D_F32 in project BoofCV by lessthanoptimal.
the class LineImageOps method convert.
/**
* Find the point in which the line intersects the image border and create a line segment at those points
*/
public static LineSegment2D_F32 convert(LineParametric2D_F32 l, int width, int height) {
double t0 = (0 - l.p.x) / l.getSlopeX();
double t1 = (0 - l.p.y) / l.getSlopeY();
double t2 = (width - l.p.x) / l.getSlopeX();
double t3 = (height - l.p.y) / l.getSlopeY();
Point2D_F32 a = computePoint(l, t0);
Point2D_F32 b = computePoint(l, t1);
Point2D_F32 c = computePoint(l, t2);
Point2D_F32 d = computePoint(l, t3);
List<Point2D_F32> inside = new ArrayList<>();
checkAddInside(width, height, a, inside);
checkAddInside(width, height, b, inside);
checkAddInside(width, height, c, inside);
checkAddInside(width, height, d, inside);
if (inside.size() != 2) {
return null;
// System.out.println("interesting");
}
return new LineSegment2D_F32(inside.get(0), inside.get(1));
}
use of georegression.struct.line.LineSegment2D_F32 in project BoofCV by lessthanoptimal.
the class ImageLinePanel method paintComponent.
@Override
public synchronized void paintComponent(Graphics g) {
super.paintComponent(g);
if (background == null)
return;
Graphics2D g2 = (Graphics2D) g;
int w = background.getWidth();
int h = background.getHeight();
double scaleX = getWidth() / (double) w;
double scaleY = getHeight() / (double) h;
double scale = Math.min(scaleX, scaleY);
if (scale > 1) {
scale = 1;
}
g2.drawImage(background, 0, 0, (int) (scale * w), (int) (scale * h), 0, 0, w, h, null);
g2.setStroke(new BasicStroke(3));
for (LineSegment2D_F32 s : lines) {
g2.setColor(Color.RED);
g2.drawLine((int) (scale * s.a.x), (int) (scale * s.a.y), (int) (scale * s.b.x), (int) (scale * s.b.y));
g2.setColor(Color.BLUE);
g2.fillOval((int) (scale * s.a.x) - 1, (int) (scale * s.a.y) - 1, 3, 3);
g2.fillOval((int) (scale * s.b.x) - 1, (int) (scale * s.b.y) - 1, 3, 3);
}
}
use of georegression.struct.line.LineSegment2D_F32 in project BoofCV by lessthanoptimal.
the class CommonGridRansacLineDetectorChecks method checkObvious.
/**
* Give it a single straight line and see if it can detect it. Allow the region size to be changed to check
* for issues related to that
* @param regionSize
*/
protected void checkObvious(int regionSize) {
// System.out.println("regionSize = "+regionSize);
int where = 25;
GrayU8 edgeImage = 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++) {
edgeImage.set(where, i, 1);
GeneralizedImageOps.set(derivX, where, i, 20);
}
ModelManagerLinePolar2D_F32 manager = new ModelManagerLinePolar2D_F32();
GridLineModelDistance distance = new GridLineModelDistance(0.9f);
GridLineModelFitter fitter = new GridLineModelFitter(0.9f);
ModelMatcher<LinePolar2D_F32, Edgel> matcher = new Ransac<>(123123, manager, fitter, distance, 25, 1);
GridRansacLineDetector<D> alg = createDetector(regionSize, 5, matcher);
alg.process(derivX, derivY, edgeImage);
MatrixOfList<LineSegment2D_F32> lines = alg.getFoundLines();
assertEquals(width / regionSize, lines.getWidth());
assertEquals(height / regionSize, lines.getHeight());
int gridCol = where / regionSize;
for (int i = 0; i < lines.height; i++) {
List<LineSegment2D_F32> l = lines.get(gridCol, i);
assertTrue(l.size() == 1);
LineSegment2D_F32 a = l.get(0);
assertTrue(Math.abs(a.slopeY()) > 1);
assertTrue(Math.abs(a.slopeX()) < 0.01);
}
}
use of georegression.struct.line.LineSegment2D_F32 in project BoofCV by lessthanoptimal.
the class TestConnectLinesGrid method checkAngleTolerance.
/**
* Makes sure the angle tolerance parameter is correctly set and processed
*/
@Test
public void checkAngleTolerance() {
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, 0, 4, 4));
// have the tolerance be too tight
ConnectLinesGrid app = new ConnectLinesGrid(0.1, 1, 1);
app.process(grid);
assertEquals(2, grid.createSingleList().size());
// now make the tolerance broader
app = new ConnectLinesGrid(Math.PI, 1, 1);
app.process(grid);
assertEquals(1, grid.createSingleList().size());
}
Aggregations