Search in sources :

Example 1 with PositionPatternNode

use of boofcv.alg.fiducial.qrcode.PositionPatternNode in project BoofCV by lessthanoptimal.

the class TestMicroQrCodeDecoderImage method transposed.

/**
 * Transposes the input image and sees if it can still be decoded by default
 */
@Test
void transposed() {
    MicroQrCode qr = new MicroQrCodeEncoder().addAutomatic("123LK").fixate();
    GrayU8 image = render(qr);
    GrayU8 imageTransposed = image.createSameShape();
    ImageMiscOps.transpose(image, imageTransposed);
    var patterns = new DogArray<>(PositionPatternNode::new);
    addPositionPattern(qr, patterns);
    var alg = new MicroQrCodeDecoderImage<>(null, "", GrayU8.class);
    alg.process(patterns.toList(), imageTransposed);
    assertEquals(1, alg.found.size());
    assertEquals(0, alg.failures.size());
    assertEquals("123LK", alg.found.get(0).message);
    // It should fail now since it won't consider a transposed marker
    alg.considerTransposed = false;
    alg.process(patterns.toList(), imageTransposed);
    assertEquals(0, alg.found.size());
    assertEquals(1, alg.failures.size());
}
Also used : GrayU8(boofcv.struct.image.GrayU8) PositionPatternNode(boofcv.alg.fiducial.qrcode.PositionPatternNode) DogArray(org.ddogleg.struct.DogArray) Test(org.junit.jupiter.api.Test)

Example 2 with PositionPatternNode

use of boofcv.alg.fiducial.qrcode.PositionPatternNode 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 3 with PositionPatternNode

use of boofcv.alg.fiducial.qrcode.PositionPatternNode in project BoofCV by lessthanoptimal.

the class TestMicroQrCodeDecoderImage method simple_rotateSquare.

/**
 * Rotate the square and see if it can always decode it
 */
@Test
void simple_rotateSquare() {
    MicroQrCode qr = new MicroQrCodeEncoder().addAutomatic("123LK").fixate();
    GrayU8 image = render(qr);
    var patterns = new DogArray<>(PositionPatternNode::new);
    PositionPatternNode pp = addPositionPattern(qr, patterns);
    var alg = new MicroQrCodeDecoderImage<>(null, "", GrayU8.class);
    for (int i = 0; i < 4; i++) {
        alg.process(patterns.toList(), image);
        assertEquals(1, alg.found.size());
        assertEquals(0, alg.failures.size());
        assertEquals("123LK", alg.found.get(0).message);
        // Rotate the polygon so that it now needs to compensate for that
        UtilPolygons2D_F64.shiftDown(pp.square);
    }
}
Also used : GrayU8(boofcv.struct.image.GrayU8) PositionPatternNode(boofcv.alg.fiducial.qrcode.PositionPatternNode) DogArray(org.ddogleg.struct.DogArray) Test(org.junit.jupiter.api.Test)

Example 4 with PositionPatternNode

use of boofcv.alg.fiducial.qrcode.PositionPatternNode in project BoofCV by lessthanoptimal.

the class TestMicroQrCodeDecoderImage method decode_byte.

/**
 * Decode a marker with byte encoded data
 */
@Test
void decode_byte() {
    MicroQrCode qr = new MicroQrCodeEncoder().addBytes("123LK%$63").fixate();
    GrayU8 image = render(qr);
    var patterns = new DogArray<>(PositionPatternNode::new);
    addPositionPattern(qr, patterns);
    var alg = new MicroQrCodeDecoderImage<>(null, "", GrayU8.class);
    alg.process(patterns.toList(), image);
    assertEquals(1, alg.found.size());
    assertEquals(0, alg.failures.size());
    assertEquals("123LK%$63", alg.found.get(0).message);
}
Also used : GrayU8(boofcv.struct.image.GrayU8) PositionPatternNode(boofcv.alg.fiducial.qrcode.PositionPatternNode) DogArray(org.ddogleg.struct.DogArray) Test(org.junit.jupiter.api.Test)

Example 5 with PositionPatternNode

use of boofcv.alg.fiducial.qrcode.PositionPatternNode in project BoofCV by lessthanoptimal.

the class TestMicroQrCodeDecoderImage method addPositionPattern.

private PositionPatternNode addPositionPattern(MicroQrCode qr, DogArray<PositionPatternNode> patterns) {
    PositionPatternNode pp = patterns.grow();
    pp.square = qr.pp;
    pp.grayThreshold = 127;
    return pp;
}
Also used : PositionPatternNode(boofcv.alg.fiducial.qrcode.PositionPatternNode)

Aggregations

PositionPatternNode (boofcv.alg.fiducial.qrcode.PositionPatternNode)5 DogArray (org.ddogleg.struct.DogArray)4 Test (org.junit.jupiter.api.Test)4 GrayU8 (boofcv.struct.image.GrayU8)3 FiducialImageEngine (boofcv.alg.drawing.FiducialImageEngine)1 ErrorLevel (boofcv.alg.fiducial.microqr.MicroQrCode.ErrorLevel)1