use of boofcv.struct.PointIndex_I32 in project BoofCV by lessthanoptimal.
the class ExampleFitPolygon method fitCannyEdges.
/**
* Fits a sequence of line-segments into a sequence of points found using the Canny edge detector. In this case
* the points are not connected in a loop. The canny detector produces a more complex tree and the fitted
* points can be a bit noisy compared to the others.
*/
public static void fitCannyEdges(GrayF32 input) {
BufferedImage displayImage = new BufferedImage(input.width, input.height, BufferedImage.TYPE_INT_RGB);
// Finds edges inside the image
CannyEdge<GrayF32, GrayF32> canny = FactoryEdgeDetectors.canny(2, true, true, GrayF32.class, GrayF32.class);
canny.process(input, 0.1f, 0.3f, null);
List<EdgeContour> contours = canny.getContours();
Graphics2D g2 = displayImage.createGraphics();
g2.setStroke(new BasicStroke(2));
// used to select colors for each line
Random rand = new Random(234);
for (EdgeContour e : contours) {
g2.setColor(new Color(rand.nextInt()));
for (EdgeSegment s : e.segments) {
// fit line segments to the point sequence. Note that loop is false
List<PointIndex_I32> vertexes = ShapeFittingOps.fitPolygon(s.points, false, minSide, cornerPenalty);
VisualizeShapes.drawPolygon(vertexes, false, g2);
}
}
gui.addImage(displayImage, "Canny Trace");
}
use of boofcv.struct.PointIndex_I32 in project BoofCV by lessthanoptimal.
the class ShapeFitContourApp method renderVisuals.
protected void renderVisuals(Graphics2D g2, double scale) {
BoofSwingUtil.antialiasing(g2);
int activeAlg = controlPanel.getSelectedAlgorithm();
g2.setStroke(new BasicStroke(3));
if (controlPanel.contoursVisible) {
g2.setStroke(new BasicStroke(1));
VisualizeBinaryData.render(contours, null, Color.CYAN, 1.0, scale, g2);
}
if (activeAlg == 0) {
double cornerPalty = controlPanel.getCornerPenalty();
int minimumSplitPixels = controlPanel.getMinimumSplitPixels();
for (Contour c : contours) {
List<PointIndex_I32> vertexes = ShapeFittingOps.fitPolygon(c.external, true, minimumSplitPixels, cornerPalty);
g2.setColor(Color.RED);
visualizePolygon(g2, scale, vertexes);
for (List<Point2D_I32> internal : c.internal) {
vertexes = ShapeFittingOps.fitPolygon(internal, true, minimumSplitPixels, cornerPalty);
g2.setColor(Color.GREEN);
visualizePolygon(g2, scale, vertexes);
}
}
} else if (activeAlg == 1) {
// Filter small contours since they can generate really wacky ellipses
for (Contour c : contours) {
if (c.external.size() > 10) {
FitData<EllipseRotated_F64> ellipse = ShapeFittingOps.fitEllipse_I32(c.external, 0, false, null);
g2.setColor(Color.RED);
g2.setStroke(new BasicStroke(2.5f));
VisualizeShapes.drawEllipse(ellipse.shape, scale, g2);
}
for (List<Point2D_I32> internal : c.internal) {
if (internal.size() <= 10)
continue;
FitData<EllipseRotated_F64> ellipse = ShapeFittingOps.fitEllipse_I32(internal, 0, false, null);
g2.setColor(Color.GREEN);
g2.setStroke(new BasicStroke(2.5f));
VisualizeShapes.drawEllipse(ellipse.shape, scale, g2);
}
}
}
}
Aggregations