Search in sources :

Example 1 with ErrorLevel

use of boofcv.alg.fiducial.microqr.MicroQrCode.ErrorLevel in project BoofCV by lessthanoptimal.

the class TestMicroQrCodeDecoderImage method simple_all_configs.

/**
 * Render then decode images with all possible versions, masks, and error correction levels.
 */
@Test
void simple_all_configs() {
    String message = "01234";
    var engine = new FiducialImageEngine();
    engine.configure(0, 100);
    var generator = new MicroQrCodeGenerator();
    generator.markerWidth = 100;
    generator.setRender(engine);
    var alg = new MicroQrCodeDecoderImage<>(null, "", GrayU8.class);
    var patterns = new DogArray<>(PositionPatternNode::new);
    for (int version = 1; version <= 4; version++) {
        ErrorLevel[] errors = MicroQrCode.allowedErrorCorrection(version);
        for (ErrorLevel error : errors) {
            // Generate the QR code
            var encoder = new MicroQrCodeEncoder();
            // encoder.setVerbose(System.out, null);
            MicroQrCode qr = encoder.setVersion(version).setError(error).setMask(M00).addNumeric(message).fixate();
            generator.render(qr);
            // Set up the "detected" position pattern
            patterns.reset();
            PositionPatternNode pp = patterns.grow();
            pp.square = qr.pp;
            pp.grayThreshold = (double) (engine.getWhite() / 2);
            // ShowImages.showWindow(engine.getGray(), "Title");
            // BoofMiscOps.sleep(10_000);
            // Process the image
            // alg.decoder.setVerbose(System.out, null);
            alg.process(patterns.toList(), engine.getGray());
            // Check results
            assertEquals(1, alg.found.size());
            assertEquals(0, alg.failures.size());
            assertEquals(version, alg.found.get(0).version);
            assertEquals(message, alg.found.get(0).message);
        }
    }
}
Also used : FiducialImageEngine(boofcv.alg.drawing.FiducialImageEngine) ErrorLevel(boofcv.alg.fiducial.microqr.MicroQrCode.ErrorLevel) PositionPatternNode(boofcv.alg.fiducial.qrcode.PositionPatternNode) DogArray(org.ddogleg.struct.DogArray) Test(org.junit.jupiter.api.Test)

Example 2 with ErrorLevel

use of boofcv.alg.fiducial.microqr.MicroQrCode.ErrorLevel in project BoofCV by lessthanoptimal.

the class TestMicroQrCode method encodeAndDecodeFormat.

/**
 * Go through all possible version and error levels and see if they are correctly decoded
 */
@Test
void encodeAndDecodeFormat() {
    var qr = new MicroQrCode();
    var found = new MicroQrCode();
    for (int version = 1; version <= 4; version++) {
        qr.version = version;
        ErrorLevel[] levels = MicroQrCode.allowedErrorCorrection(version);
        for (ErrorLevel error : levels) {
            qr.error = error;
            assertTrue(found.decodeFormatBits(qr.encodeFormatBits()));
            assertEquals(qr.version, found.version);
            assertEquals(qr.error, found.error);
        }
    }
}
Also used : ErrorLevel(boofcv.alg.fiducial.microqr.MicroQrCode.ErrorLevel) Test(org.junit.jupiter.api.Test)

Aggregations

ErrorLevel (boofcv.alg.fiducial.microqr.MicroQrCode.ErrorLevel)2 Test (org.junit.jupiter.api.Test)2 FiducialImageEngine (boofcv.alg.drawing.FiducialImageEngine)1 PositionPatternNode (boofcv.alg.fiducial.qrcode.PositionPatternNode)1 DogArray (org.ddogleg.struct.DogArray)1