use of boofcv.alg.shapes.FitData in project BoofCV by lessthanoptimal.
the class ShapeFitContourApp method renderVisuals.
protected void renderVisuals(Graphics2D g2, double scale) {
int activeAlg = controlPanel.getSelectedAlgorithm();
g2.setStroke(new BasicStroke(3));
g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
if (controlPanel.contoursVisible) {
g2.setStroke(new BasicStroke(1));
VisualizeBinaryData.render(contours, null, Color.CYAN, 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