Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error decoding some QR codes with error correction level H #506

Open
Anlo2846 opened this issue Jun 30, 2023 · 1 comment
Open

Error decoding some QR codes with error correction level H #506

Anlo2846 opened this issue Jun 30, 2023 · 1 comment

Comments

@Anlo2846
Copy link

First of all, thanks for a great library. I have discovered an issue decoding QR codes using error correction level H. I'm running the latest version 0.16.9 from NuGet.

      BarcodeWriter writer = new BarcodeWriter()
      {
        Format = BarcodeFormat.QR_CODE,
      };

      BarcodeReader reader = new BarcodeReader()
      {
        Options = new DecodingOptions()
        {
          PossibleFormats = new List<BarcodeFormat>()
          {
            BarcodeFormat.QR_CODE,
          },
        },
      };

      Trace.WriteLine($"Level\tPixel size\tSuffix\tSuccess");
      foreach(ErrorCorrectionLevel level in new[] { ErrorCorrectionLevel.L, ErrorCorrectionLevel.M, ErrorCorrectionLevel.Q, ErrorCorrectionLevel.H })
      {
        foreach(int pixelSize in new[] { 2, 4, 8 })
        {
          foreach(string suffix in new[] { "", "suffix" })
          {
            writer.Options = new QrCodeEncodingOptions()
            {
              QrVersion = 6,
              ErrorCorrection = level,
              Width  = 49 * pixelSize,
              Height = 49 * pixelSize,
            };

            using Bitmap bmp = writer.Write("WIFI:S:Maskinutbildning;T:WPA;P:fWpzCSgnxe;;" + suffix);
            Result result = reader.Decode(bmp);
            Trace.WriteLine($"{level}\t{pixelSize}\t{suffix.Length > 0}\t{result != null}");
          }
        }
      }

This produces the output:

Level	Pixel size	Suffix	Success
L	2	False	True
L	2	True	True
L	4	False	True
L	4	True	True
L	8	False	True
L	8	True	True
M	2	False	True
M	2	True	True
M	4	False	True
M	4	True	True
M	8	False	True
M	8	True	True
Q	2	False	True
Q	2	True	True
Q	4	False	True
Q	4	True	True
Q	8	False	True
Q	8	True	True
H	2	False	True
H	2	True	True
H	4	False	False
H	4	True	True
H	8	False	False
H	8	True	True

As you can see, error correction level H is only decoded correctly when using pixel size 2. The strange thing is that if I add some more text to the QR code it decodes fine. Also if I change the password field to something other. So I guess that this exact string creates some difficult pattern in the code.

I tried an online QR code generator with the same string and error correction level H which is also not decoded by ZXing.Net.

@micjahn
Copy link
Owner

micjahn commented Jul 18, 2023

There is something wrong with the detector if the default mode is used.
If you switch to PureBarcode mode success will be true in all cases.

                Options = new DecodingOptions()
                {
                    PureBarcode = true,
                    PossibleFormats = new List<BarcodeFormat>()
...

PureBarcode mode should only be used for "synthetic" images. It doesn't work with real-world captured images.
Sorry, I don't have any idea how to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants