micjahn/ZXing.Net

ZXing.Net doesn't seem to be able scan more complicated PDF417 barcodes

gtvracer opened this issue · 12 comments

Using ZXing.Net.Maui.Controls v0.4.0, which is based on ZXing.Net library, and the basic ZXing page and configuration, it can detect simple PDF417, but it fails to detect more complex ones, like the one on the back of a California drivers license. It also doesn't keep the torch on either, but flashes once when the page initializes. I've tried the barcode images samples on the internet by searching for "PDF417 images", only the simple ones are read....

I've tried two other packages, both based on ZXing.Net, BarcodeScanning.Native.Maui and Camera.MAUI/Camera.MAUI.ZXing. Neither works either for complex PDF417.

The Xamarin version of ZXing is able to read the CA drivers license barcode, fyi..

I'm using Visual Studio v17.9.2, XCode 15.3 and .net8.

Any insight will be appreciated.
This PDF417 scanning is for an app the County of Santa Cruz, CA is creating for our local law enforcement, so any help will be appreciated!!

Thanks!

Page:

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:zxing="clr-namespace:ZXing.Net.Maui.Controls;assembly=ZXing.Net.MAUI.Controls"
             x:Class="MyProject.Views.ScanPage"
             Title="ScanPage">   
        <zxing:CameraBarcodeReaderView
			x:Name="barcodeView"
                        IsTorchOn="True"
			BarcodesDetected="BarcodesDetected" />        
</ContentPage>

Code behind:

public partial class ScanPage : ContentPage
{
	public ScanPage()
	{
		InitializeComponent();
        BindingContext = this;

        barcodeView.Options = new ZXing.Net.Maui.BarcodeReaderOptions()
        {
            TryHarder = true,
            AutoRotate = true,
            Multiple = true,
            Formats = BarcodeFormats.TwoDimensional // | ZXing.Net.Maui.BarcodeFormat.QrCode | BarcodeFormat.Pdf417 
        };
        barcodeView.IsTorchOn = true;
	}

    protected void BarcodesDetected(object sender, BarcodeDetectionEventArgs e)
    {
        foreach (var barcode in e.Results)
        { // dumps to Debug.WriteLine()...
            App.Log($"Barcode: {barcode.Format} -> {barcode.Value}");
        }

        var first = e.Results?.FirstOrDefault();
        if (first != null)
        {
            Dispatcher.DispatchAsync(async () =>
            {
                await DisplayAlert("Barcode detected", first.Value, "OK");
            });
        }
    }
}

MauiProgram.cs:

public static class MauiProgram
  {
      public static MauiApp CreateMauiApp()
      {
          var builder = MauiApp.CreateBuilder();
          builder
              .UseMauiApp<App>()
              .UseMauiCommunityToolkit()
              .UseBarcodeReader()
              .ConfigureFonts(fonts =>
              {
                  fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                  fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
              })
              .ConfigureMauiHandlers(handlers =>
              {
                  handlers.AddHandler(typeof(PillCheckbox), typeof(PillCheckboxRenderer));
              });

          builder.Services.AddSingleton<IImageInfo, ImageInfo>();

#if DEBUG
          builder.Logging.AddDebug();
#endif

          var app = builder.Build();

          //ServiceProviderHelper.Initialize(app.Services);
          return app;
      }
  }

Can you give an example of what you consider to be a "complex" PDF417 symbol and therefore fails to be decoded with ZXing.NET?

Hi Tom, no, I'm not Mike, I'm the maintainer of the zxing-cpp project. I re-implemented a bunch of the detector algorithms but the PDF417 detector is still mostly the one from the original Java ZXing library. I assume ZXing.NET's version is also a 1 to 1 port from the Java code. So all three should behave the same, which is contradicted by your your observation that the Xamarin version of ZXing is working. So I was curious what zxing-cpp does with your specific sample.

Maybe there is something wrong with the bing search link you provided. I get this image if I follow that link. My zxing-bench tool that compares the ZXing.NET implementation with the .NET wrapper of zxing-cpp shows that both detect two barcodes in that image, a Code128 and a PDF417 one. So both work just fine with this image (although my implementation is 30x faster ;)).

I have no experience with zxing.net.maui. I was referring to https://www.nuget.org/packages/ZXing.Net and my benchmark tool is currently using 0.16.14.

CORRECTION: I'm using https://www.nuget.org/packages/ZXing.Net.Bindings.SkiaSharp/ version 0.16.14 and that is depending on https://www.nuget.org/packages/ZXing.Net version 0.16.9.