lessthanoptimal / BoofCV

Fast computer vision library for SFM, calibration, fiducials, tracking, image processing, and more.
http://boofcv.org
1.09k stars 260 forks source link

Micro QR-codes are not detected #395

Open acriba opened 1 year ago

acriba commented 1 year ago

We are trying to use nano qr codes because we need to encode very little information and would like to minimize size. The codes are mostly detected but there are some qr codes that can't be decoded and I have no idea where the problem lies. It seems that somehow the position of the qr code is completely misdetected, which results in an error ERROR_CORRECTION. I have painted the detected bounding boxes above the samples. I include also a few succesful examples - I don't have an idea why the boundaries are not detected correctly in these cases. The qr-codes are generated with boofcv. Maybe somebody has a hint or something can be improved?

success03 success02 success01 error03 error02 error01
lessthanoptimal commented 1 year ago

Can you post the miss detections without any overlays? Also what software did you use to generate the micro QR.

Just looking at your annotation, the issue is that for some reason it has a boundary box that's the wrong size. This could be caused by a localization error in the small pattern in the top left. The boundary box being at the wrong location is an artifact of it trying all 4 possible orientations before giving up.

Are you thresholding the image first before processing? It might work better without thresholding. It uses information from the gray scale aliasing to fit a better shape to the marker.

On Fri, Jun 9, 2023 at 1:48 AM acriba @.***> wrote:

We are trying to use nano qr codes because we need to encode very little information and would like to minimize size. The codes are mostly detected but there are some qr codes that can't be decoded and I have no idea where the problem lies. It seems that somehow the position of the qr code is completely misdetected, which results in an error ERROR_CORRECTION. I have painted the detected bounding boxes above the samples. I include also a few succesful examples - I don't have an idea why the boundaries are not detected correctly in these cases. The qr-codes are generated with boofcv. Maybe somebody has a hint or something can be improved? [image: success03] https://user-images.githubusercontent.com/14861362/244641994-10fb0385-baa8-4c9d-8d2e-011bc7415791.png [image: success02] https://user-images.githubusercontent.com/14861362/244642003-fef0060e-fe90-4b12-9fdd-d5965d0252dc.png [image: success01] https://user-images.githubusercontent.com/14861362/244642007-4a7b8711-0ebe-4226-9356-78089f16b4c3.png [image: error03] https://user-images.githubusercontent.com/14861362/244642011-25d47c41-195f-4a21-a5c7-3b21334d9676.png [image: error02] https://user-images.githubusercontent.com/14861362/244642019-65b35bc4-131c-4f1f-b2a5-e6910308dc85.png [image: error01] https://user-images.githubusercontent.com/14861362/244642022-288c51b3-10bb-4b01-905f-523e2e22128a.png

— Reply to this email directly, view it on GitHub https://github.com/lessthanoptimal/BoofCV/issues/395, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFUOVYYQNVZYNVU7M3GEODXKLPMBANCNFSM6AAAAAAZALA6SA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

-- "Now, now my good man, this is no time for making enemies." — Voltaire (1694-1778), on his deathbed in response to a priest asking that he renounce Satan.

acriba commented 1 year ago

Hello Peter, I appreciate your your help - thank you very much.

We are using BoofCV to create the Micro QR code (sorry for using the wrong name before). We are not using thresholding, we convert the original image with to a grayscale image.

I have attached the grayscale image gray that is used by the detector. We convert the original color image with ConvertBufferedImage.convertFromSingle(original, null, GrayU8.class);:

    var config = new ConfigMicroQrCode();
    MicroQrCodeDetector<GrayU8> detector = FactoryFiducial.microqr(config, GrayU8.class);
    detector.process(gray);

Christian error_gray_original_03 error_gray_original_02 error_gray_original_01

lessthanoptimal commented 1 year ago

Sorry for taking a bit to reply. The images you posted look a bit noisy. Can you paste the code you used to generate these markers? It's also possible that they are somehow in an illegal state. I hope to be able to dive into this soon.

acriba commented 1 year ago

Hello Peter,

here would be the code that we are using to generate the Codes:

public byte[] getMicroQrCode() {

    MicroQrCode qr = new MicroQrCodeEncoder()
            .setError(MicroQrCode.ErrorLevel.M)
            .addAutomatic(getData())
            .fixate();

    GrayU8 rendered = MicroQrCodeGenerator.renderImage(3, 2, qr);
    BufferedImage image = ConvertBufferedImage.convertTo(rendered, null);

    try(ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
        ImageIO.write(image, "png", baos);
        return baos.toByteArray();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

}

I don't think the codes could end up in an illegal state?

Christian