micjahn / ZXing.Net

.Net port of the original java-based barcode reader and generator library zxing
Apache License 2.0
2.69k stars 665 forks source link

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

Open gtvracer opened 5 months ago

gtvracer commented 5 months ago

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;
      }
  }
axxel commented 5 months ago

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

gtvracer commented 5 months ago

Hello Axxel,Are you Mike?  Anyway, thanks for responding :)I will get you specific examples tomorrow when I’m at work and have access to a physical development iPhone. The problematic barcodes can be found also, if you googled for “images driver license pdf417” and select the images tab.  You will find the ones like I’m trying to read.  Thanks,TomOn Apr 7, 2024, at 8:48 AM, axxel @.***> wrote: Can you give an example of what you consider to be a "complex" PDF417 symbol and therefore fails to be decoded with ZXing.NET?

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

axxel commented 5 months ago

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.

gtvracer commented 5 months ago

Yes, it’s peculiar then..The Xamarin implementation has no problem with the driver license barcode, but in its Maui version, it seems to read simple pdf417s but not the ones for a DL. I tried three packages that wrap the core Zxing library with a ContentPage but all three fail to read it.  I tried feeding a captured image directly to the reader, but it gave an error, something about it expecting one pattern but getting another.  I’m sorry that I can’t give you the exact error right now.  But I could tomorrow. Thanks,TomOn Apr 7, 2024, at 10:00 AM, axxel @.***> wrote: 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.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

gtvracer commented 5 months ago

I can send you my DL pic.  But directly to you, as I don’t know who else can view this thread?Just don’t need my PII spread over the net ;-)Thanks,TomOn Apr 7, 2024, at 10:40 AM, Tom Tong @.> wrote:Yes, it’s peculiar then..The Xamarin implementation has no problem with the driver license barcode, but in its Maui version, it seems to read simple pdf417s but not the ones for a DL. I tried three packages that wrap the core Zxing library with a ContentPage but all three fail to read it.  I tried feeding a captured image directly to the reader, but it gave an error, something about it expecting one pattern but getting another.  I’m sorry that I can’t give you the exact error right now.  But I could tomorrow. Thanks,TomOn Apr 7, 2024, at 10:00 AM, axxel @.> wrote: 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.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

gtvracer commented 4 months ago

Hi Axxel,

Here is an image that returns null result... Thanks Tom

[image: pdf417-1.PNG]

On Sun, Apr 7, 2024 at 11:12 AM Tom Tong @.***> wrote:

I can send you my DL pic. But directly to you, as I don’t know who else can view this thread?

Just don’t need my PII spread over the net ;-) Thanks, Tom

On Apr 7, 2024, at 10:40 AM, Tom Tong @.***> wrote:

Yes, it’s peculiar then..

The Xamarin implementation has no problem with the driver license barcode, but in its Maui version, it seems to read simple pdf417s but not the ones for a DL.

I tried three packages that wrap the core Zxing library with a ContentPage but all three fail to read it. I tried feeding a captured image directly to the reader, but it gave an error, something about it expecting one pattern but getting another. I’m sorry that I can’t give you the exact error right now. But I could tomorrow.

Thanks, Tom

On Apr 7, 2024, at 10:00 AM, axxel @.***> wrote:



Hi Tom, no, I'm not Mike, I'm the maintainer of the zxing-cpp https://github.com/zxing-cpp/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.

— Reply to this email directly, view it on GitHub https://github.com/micjahn/ZXing.Net/issues/557#issuecomment-2041530291, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACDPXLSNZS453SAYCDIVCLTY4F3TDAVCNFSM6AAAAABE56NNPOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBRGUZTAMRZGE . You are receiving this because you authored the thread.Message ID: @.***>

gtvracer commented 4 months ago

Here is a link to the image: https://www.bing.com/images/search?view=detailV2&ccid=Ss6OGv4g&id=E6A2E8947ADD25E7314DD826338FFE6EF9CA9A65&thid=OIP.Ss6OGv4g3YJACytkgc4l-AHaEX&mediaurl=https%3a%2f%2fidtempl.com%2fwp-content%2fuploads%2f2022%2f04%2fScreenshot-2022-06-04-135541.jpg&cdnurl=https%3a%2f%2fth.bing.com%2fth%2fid%2fR.4ace8e1afe20dd82400b2b6481ce25f8%3frik%3dZZrK%252bW7%252bjzMm2A%26pid%3dImgRaw%26r%3d0&exph=730&expw=1236&q=driver+license+pdf417+images&simid=608009873378706014&FORM=IRPRST&ck=265CE94CD1C8581457D5EBA75B6B4D6F&selectedIndex=0&itb=0&ajaxhist=0&ajaxserp=0

axxel commented 4 months ago

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 ;)).

gtvracer commented 4 months ago

The zxing.net 0.40.0 for c# used in zxing.net.maui and zxing.net.maui.controls the same package you’re using?  I’ve tried zxing barcode reader by giving it a png file directly and also using the contentpage wrapper methods and neither returns any result.  I’m using VS 17.9.4, Xcode 15.3 and .net8 to make a native iPhone app. Thanks,TomOn Apr 8, 2024, at 3:40 PM, axxel @.***> wrote: 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 ;)).

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

gtvracer commented 4 months ago

Oops... sort of had the package versions wrong... was going off the top of my head..

[image: image.png]

So the Zxing.net.maui is 0.4.0, but the underlying zxing.net is 0.16.9

On Mon, Apr 8, 2024 at 3:57 PM Tom Tong @.***> wrote:

The zxing.net 0.40.0 for c# used in zxing.net.maui and zxing.net.maui.controls the same package you’re using?

I’ve tried zxing barcode reader by giving it a png file directly and also using the contentpage wrapper methods and neither returns any result.

I’m using VS 17.9.4, Xcode 15.3 and .net8 to make a native iPhone app.

Thanks, Tom

On Apr 8, 2024, at 3:40 PM, axxel @.***> wrote:



Maybe there is something wrong with the bing search link you provided. I get this image https://idtempl.com/wp-content/uploads/2022/04/Screenshot-2022-06-04-135541.jpg if I follow that link. My zxing-bench https://github.com/axxel/zxing-bench/blob/main/dotnet/README.md tool that compares the ZXing.NET implementation with the .NET wrapper https://www.nuget.org/packages/ZXingCpp 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 ;)).

— Reply to this email directly, view it on GitHub https://github.com/micjahn/ZXing.Net/issues/557#issuecomment-2043756462, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACDPXLUCFP2K4FRH7DKMLWLY4MMFNAVCNFSM6AAAAABE56NNPOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBTG42TMNBWGI . You are receiving this because you authored the thread.Message ID: @.***>

axxel commented 4 months ago

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.

gtvracer commented 4 months ago

This issue is probably very specific to Maui/iOS/net8/Zxing 0.16.9/C# environment Thanks,TomOn Apr 8, 2024, at 4:40 PM, axxel @.***> wrote: 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.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>