Search in sources :

Example 1 with FitData

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);
            }
        }
    }
}
Also used : Contour(boofcv.alg.filter.binary.Contour) PointIndex_I32(boofcv.struct.PointIndex_I32) Point2D_I32(georegression.struct.point.Point2D_I32) ArrayList(java.util.ArrayList) List(java.util.List) FitData(boofcv.alg.shapes.FitData)

Aggregations

Contour (boofcv.alg.filter.binary.Contour)1 FitData (boofcv.alg.shapes.FitData)1 PointIndex_I32 (boofcv.struct.PointIndex_I32)1 Point2D_I32 (georegression.struct.point.Point2D_I32)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1