Search in sources :

Example 1 with AztecEncoder

use of boofcv.alg.fiducial.aztec.AztecEncoder in project BoofCV by lessthanoptimal.

the class BenchmarkAztecCodeDetector method setup.

/**
 * Generate a set of synthetic images with two markers in it to test against
 */
@Setup
public void setup() {
    var rand = new Random(BoofTesting.BASE_SEED);
    AztecCode marker1 = new AztecEncoder().addAutomatic("small").fixate();
    AztecCode marker2 = new AztecEncoder().addAutomatic("Much Larger Than the Oth9er!!#").fixate();
    GrayU8 image1 = AztecGenerator.renderImage(5, 0, marker1);
    GrayU8 image2 = AztecGenerator.renderImage(5, 0, marker2);
    var fullImage = new GrayU8(image1.width + image2.width + 50, image1.width + image2.width + 100);
    GImageMiscOps.fillUniform(fullImage, rand, 50, 150);
    GImageMiscOps.copy(0, 0, 10, 15, image1.width, image1.height, image1, fullImage);
    GImageMiscOps.copy(0, 0, 20 + image1.width, 50, image2.width, image2.height, image2, fullImage);
    images.add(fullImage);
    // manually checked that all the distorted images have markers inside the image
    for (int i = 0; i < 4; i++) {
        GrayU8 distorted = fullImage.createSameShape();
        new FDistort(fullImage, distorted).affine(1.0 + rand.nextGaussian() * 0.1, rand.nextGaussian() * 0.01, rand.nextGaussian() * 0.01, 1.0 + rand.nextGaussian() * 0.1, rand.nextGaussian() * 0.5, rand.nextGaussian() * 0.5).apply();
        images.add(distorted);
    }
}
Also used : Random(java.util.Random) FDistort(boofcv.abst.distort.FDistort) AztecCode(boofcv.alg.fiducial.aztec.AztecCode) GrayU8(boofcv.struct.image.GrayU8) AztecEncoder(boofcv.alg.fiducial.aztec.AztecEncoder)

Example 2 with AztecEncoder

use of boofcv.alg.fiducial.aztec.AztecEncoder in project BoofCV by lessthanoptimal.

the class CreateAztecCodeGui method renderPreview.

private void renderPreview() {
    AztecEncoder encoder = new AztecEncoder().setStructure(controls.structure);
    if (controls.errorFraction >= 0) {
        encoder.setEcc(controls.errorFraction);
    }
    if (controls.numLayers > 0) {
        encoder.setLayers(controls.numLayers);
    }
    encoder.addAutomatic(controls.message);
    GrayU8 preview = null;
    try {
        preview = AztecGenerator.renderImage(10, 0, encoder.fixate());
    } catch (RuntimeException e) {
        System.err.println("Render Failed! " + e.getClass().getSimpleName() + " " + e.getMessage());
    // e.printStackTrace();
    }
    if (preview == null) {
        BufferedImage output = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = output.createGraphics();
        g2.setColor(Color.RED);
        g2.fillRect(0, 0, output.getWidth(), output.getHeight());
        imagePanel.setImageRepaint(output);
    } else {
        BufferedImage output = new BufferedImage(preview.width, preview.height, BufferedImage.TYPE_INT_RGB);
        ConvertBufferedImage.convertTo(preview, output);
        imagePanel.setImageRepaint(output);
    }
}
Also used : GrayU8(boofcv.struct.image.GrayU8) AztecEncoder(boofcv.alg.fiducial.aztec.AztecEncoder) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 3 with AztecEncoder

use of boofcv.alg.fiducial.aztec.AztecEncoder in project BoofCV by lessthanoptimal.

the class ExampleRenderAztecCode method main.

public static void main(String[] args) {
    // Create a marker to render. Almost everything about how the marker is constructed can be manually specified
    // or you can let it automatically select everything
    AztecCode marker = new AztecEncoder().addAutomatic("Code 2D!").fixate();
    // NOTE: The final function you call must be fixate(), that's how it knows it's done
    // Render the marker as an image. It's also possible to render as a PDF or your own custom format
    GrayU8 rendered = AztecGenerator.renderImage(/* pixel per square */
    10, /* border squares */
    1, marker);
    // Convert it to a BufferedImage for display purposes
    BufferedImage output = ConvertBufferedImage.convertTo(rendered, null);
    // You can also save it to disk by uncommenting the line below
    // UtilImageIO.saveImage(output, "aztec.png");
    // Display the rendered marker
    ShowImages.showWindow(output, "Rendered Aztec Code", true);
}
Also used : AztecCode(boofcv.alg.fiducial.aztec.AztecCode) GrayU8(boofcv.struct.image.GrayU8) AztecEncoder(boofcv.alg.fiducial.aztec.AztecEncoder) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Aggregations

AztecEncoder (boofcv.alg.fiducial.aztec.AztecEncoder)3 GrayU8 (boofcv.struct.image.GrayU8)3 AztecCode (boofcv.alg.fiducial.aztec.AztecCode)2 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)2 BufferedImage (java.awt.image.BufferedImage)2 FDistort (boofcv.abst.distort.FDistort)1 Random (java.util.Random)1