Search in sources :

Example 76 with Polygon2D_F64

use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.

the class ExampleFiducialImage method main.

public static void main(String[] args) {
    String imagePath = UtilIO.pathExample("fiducial/image/examples/");
    String patternPath = UtilIO.pathExample("fiducial/image/patterns/");
    // String imageName = "image00.jpg";
    String imageName = "image01.jpg";
    // String imageName = "image02.jpg";
    // load the lens distortion parameters and the input image
    CameraPinholeRadial param = CalibrationIO.load(new File(imagePath, "intrinsic.yaml"));
    LensDistortionNarrowFOV lensDistortion = new LensDistortionRadialTangential(param);
    BufferedImage input = UtilImageIO.loadImage(imagePath, imageName);
    GrayF32 original = ConvertBufferedImage.convertFrom(input, true, ImageType.single(GrayF32.class));
    // Detect the fiducial
    SquareImage_to_FiducialDetector<GrayF32> detector = FactoryFiducial.squareImage(new ConfigFiducialImage(), ConfigThreshold.local(ThresholdType.LOCAL_MEAN, 21), GrayF32.class);
    // new ConfigFiducialImage(), ConfigThreshold.fixed(100), GrayF32.class);
    // give it a description of all the targets
    // 4 cm
    double width = 4;
    detector.addPatternImage(loadImage(patternPath, "ke.png", GrayF32.class), 100, width);
    detector.addPatternImage(loadImage(patternPath, "dog.png", GrayF32.class), 100, width);
    detector.addPatternImage(loadImage(patternPath, "yu.png", GrayF32.class), 100, width);
    detector.addPatternImage(loadImage(patternPath, "yu_inverted.png", GrayF32.class), 100, width);
    detector.addPatternImage(loadImage(patternPath, "pentarose.png", GrayF32.class), 100, width);
    detector.addPatternImage(loadImage(patternPath, "text_boofcv.png", GrayF32.class), 100, width);
    detector.addPatternImage(loadImage(patternPath, "leaf01.png", GrayF32.class), 100, width);
    detector.addPatternImage(loadImage(patternPath, "leaf02.png", GrayF32.class), 100, width);
    detector.addPatternImage(loadImage(patternPath, "hand01.png", GrayF32.class), 100, width);
    detector.addPatternImage(loadImage(patternPath, "chicken.png", GrayF32.class), 100, width);
    detector.addPatternImage(loadImage(patternPath, "h2o.png", GrayF32.class), 100, width);
    detector.addPatternImage(loadImage(patternPath, "yinyang.png", GrayF32.class), 100, width);
    detector.setLensDistortion(lensDistortion, param.width, param.height);
    detector.detect(original);
    // print the results
    Graphics2D g2 = input.createGraphics();
    Se3_F64 targetToSensor = new Se3_F64();
    Point2D_F64 locationPixel = new Point2D_F64();
    Polygon2D_F64 bounds = new Polygon2D_F64();
    for (int i = 0; i < detector.totalFound(); i++) {
        detector.getCenter(i, locationPixel);
        detector.getBounds(i, bounds);
        g2.setColor(new Color(50, 50, 255));
        g2.setStroke(new BasicStroke(10));
        VisualizeShapes.drawPolygon(bounds, true, 1.0, g2);
        if (detector.hasUniqueID())
            System.out.println("Target ID = " + detector.getId(i));
        if (detector.hasMessage())
            System.out.println("Message   = " + detector.getMessage(i));
        System.out.println("2D Image Location = " + locationPixel);
        if (detector.is3D()) {
            detector.getFiducialToCamera(i, targetToSensor);
            System.out.println("3D Location:");
            System.out.println(targetToSensor);
            VisualizeFiducial.drawCube(targetToSensor, param, detector.getWidth(i), 3, g2);
            VisualizeFiducial.drawLabelCenter(targetToSensor, param, "" + detector.getId(i), g2);
        } else {
            VisualizeFiducial.drawLabel(locationPixel, "" + detector.getId(i), g2);
        }
    }
    ShowImages.showWindow(input, "Fiducials", true);
}
Also used : LensDistortionNarrowFOV(boofcv.alg.distort.LensDistortionNarrowFOV) ConfigFiducialImage(boofcv.factory.fiducial.ConfigFiducialImage) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) LensDistortionRadialTangential(boofcv.alg.distort.radtan.LensDistortionRadialTangential) GrayF32(boofcv.struct.image.GrayF32) CameraPinholeRadial(boofcv.struct.calib.CameraPinholeRadial) Point2D_F64(georegression.struct.point.Point2D_F64) File(java.io.File) Se3_F64(georegression.struct.se.Se3_F64)

Example 77 with Polygon2D_F64

use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.

the class ExampleDetectBlackPolygon method processImages.

private static void processImages(String[] files, DetectPolygonBinaryGrayRefine<GrayU8> detector, ListDisplayPanel panel) {
    for (String fileName : files) {
        BufferedImage image = UtilImageIO.loadImage(UtilIO.pathExample(fileName));
        GrayU8 input = ConvertBufferedImage.convertFromSingle(image, null, GrayU8.class);
        GrayU8 binary = new GrayU8(input.width, input.height);
        // Binarization is done outside to allows creative tricks.  For example, when applied to a chessboard
        // pattern where square touch each other, the binary image is eroded first so that they don't touch.
        // The squares are expanded automatically during the subpixel optimization step.
        int threshold = (int) GThresholdImageOps.computeOtsu(input, 0, 255);
        ThresholdImageOps.threshold(input, binary, threshold, true);
        // it takes in a grey scale image and binary image
        // the binary image is used to do a crude polygon fit, then the grey image is used to refine the lines
        // using a sub-pixel algorithm
        detector.process(input, binary);
        // visualize results by drawing red polygons
        java.util.List<Polygon2D_F64> found = detector.getPolygons(null, null);
        Graphics2D g2 = image.createGraphics();
        g2.setStroke(new BasicStroke(3));
        for (int i = 0; i < found.size(); i++) {
            g2.setColor(Color.RED);
            VisualizeShapes.drawPolygon(found.get(i), true, g2, true);
            g2.setColor(Color.CYAN);
            VisualizeShapes.drawPolygonCorners(found.get(i), 2, g2, true);
        }
        panel.addImage(image, new File(fileName).getName());
    }
}
Also used : GrayU8(boofcv.struct.image.GrayU8) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64)

Example 78 with Polygon2D_F64

use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.

the class SquareBase_to_FiducialDetector method getBounds.

@Override
public Polygon2D_F64 getBounds(int which, @Nullable Polygon2D_F64 storage) {
    if (storage == null)
        storage = new Polygon2D_F64();
    else
        storage.vertexes.reset();
    FoundFiducial found = getAlgorithm().getFound().get(which);
    storage.vertexes.grow().set(found.distortedPixels.a);
    storage.vertexes.grow().set(found.distortedPixels.b);
    storage.vertexes.grow().set(found.distortedPixels.c);
    storage.vertexes.grow().set(found.distortedPixels.d);
    return storage;
}
Also used : FoundFiducial(boofcv.alg.fiducial.square.FoundFiducial) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64)

Example 79 with Polygon2D_F64

use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.

the class CalibrationFiducialDetector method selectBoundaryCorners.

/**
 * Selects points which will be the corners in the boundary. Finds the convex hull.
 */
protected void selectBoundaryCorners() {
    List<Point2D_F64> layout = detector.getLayout();
    Polygon2D_F64 hull = new Polygon2D_F64();
    UtilPolygons2D_F64.convexHull(layout, hull);
    UtilPolygons2D_F64.removeAlmostParallel(hull, 0.02);
    boundaryIndexes = new int[hull.size()];
    for (int i = 0; i < hull.size(); i++) {
        Point2D_F64 h = hull.get(i);
        boolean matched = false;
        for (int j = 0; j < layout.size(); j++) {
            if (h.isIdentical(layout.get(j), 1e-6)) {
                matched = true;
                boundaryIndexes[i] = j;
                break;
            }
        }
        if (!matched)
            throw new RuntimeException("Bug!");
    }
}
Also used : Point2D_F64(georegression.struct.point.Point2D_F64) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64)

Aggregations

Polygon2D_F64 (georegression.struct.shapes.Polygon2D_F64)79 Test (org.junit.Test)40 Point2D_F64 (georegression.struct.point.Point2D_F64)13 ArrayList (java.util.ArrayList)9 GrayU8 (boofcv.struct.image.GrayU8)6 Rectangle2D_I32 (georegression.struct.shapes.Rectangle2D_I32)6 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)5 BufferedImage (java.awt.image.BufferedImage)5 GrowQueue_B (org.ddogleg.struct.GrowQueue_B)5 Point2D_I32 (georegression.struct.point.Point2D_I32)4 PixelTransformAffine_F32 (boofcv.alg.distort.PixelTransformAffine_F32)3 DetectPolygonFromContour (boofcv.alg.shapes.polygon.DetectPolygonFromContour)3 GrayF32 (boofcv.struct.image.GrayF32)3 Affine2D_F32 (georegression.struct.affine.Affine2D_F32)3 Se3_F64 (georegression.struct.se.Se3_F64)3 Rectangle2D_F64 (georegression.struct.shapes.Rectangle2D_F64)3 File (java.io.File)3 LensDistortionNarrowFOV (boofcv.alg.distort.LensDistortionNarrowFOV)2 LensDistortionRadialTangential (boofcv.alg.distort.radtan.LensDistortionRadialTangential)2 SquareNode (boofcv.alg.fiducial.calib.squares.SquareNode)2