Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.26k stars 4.6k forks source link

[BUG]Some barcodes read successfully by older Azure.AI.FormRecognizer.DocumentAnalysis not recognized by Azure.AI.DocumentIntelligence 1.0.0-beta.3 #45650

Closed dmi-harlow closed 4 weeks ago

dmi-harlow commented 4 weeks ago

Library name and version

Azure.AI.DocumentIntelligence 1.0.0-beta.3

Describe the bug

When submitting PDFs with a clearly legible Code128 barcode to a Document Intelligence resource using the Azure.AI.DocumentIntelligence 1.0.0-beta.3 C# .NET SDK, sometimes the barcode is not recognized. When submitting the same document to the same Document Intelligence resource using Document Intelligence Studio or using the Azure.AI.FormRecognizer.DocumentAnalysis C# .NET SDK, the barcode is read successfully.

Expected behavior

Barcodes that can be read successfully via Document Intelligence Studio or the Azure.AI.FormRecognizer.DocumentAnalysis C# .NET SDK should be read successfully by the Azure.AI.DocumentIntelligence C# .NET SDK.

Actual behavior

Some barcodes that can be read successfully via Document Intelligence Studio or the Azure.AI.FormRecognizer.DocumentAnalysis C# .NET SDK are not read successfully by the Azure.AI.DocumentIntelligence C# .NET SDK.

Reproduction Steps

  1. Process the file below in Document Intelligence Studio (https://documentintelligence.ai.azure.com/studio/read) Read model, latest API version (2024-07-31 Preview), with Barcodes option on.
  2. Notice the barcode is read successfully.
  3. Run the same file through the Azure.AI.DocumentIntelligence 1.0.0-beta.3 C# .NET SDK (sample code below).
  4. Notice the barcode is not recognized.

Sample File barcode-issue-sample.pdf

Sample Code

using Azure;
using Azure.AI.DocumentIntelligence;
using Xunit;

string endpoint = "YOUR_FORM_RECOGNIZER_ENDPOINT";
string apiKey = "YOUR_FORM_RECOGNIZER_KEY";
string pdfFilePath = @"barcode-issue-sample.pdf";

var client = new DocumentIntelligenceClient(new Uri(endpoint), new AzureKeyCredential(apiKey));
using Stream pdfStream = File.OpenRead(pdfFilePath);
var content = new AnalyzeDocumentContent()
{
    Base64Source = BinaryData.FromStream(pdfStream)
};
Operation<AnalyzeResult> operation = await client.AnalyzeDocumentAsync(WaitUntil.Completed, "prebuilt-layout", analyzeRequest: content, features: [DocumentAnalysisFeature.Barcodes]);
AnalyzeResult result = operation.Value;
Assert.NotEqual(0, result.Pages[0].Barcodes.Count); // Fail

Environment


Visual Studio 2022 Developer PowerShell v17.10.6 Copyright (c) 2022 Microsoft Corporation


PS E:\Source\local\NewOcrSdkDemo> dotnet --info .NET SDK: Version: 8.0.304 Commit: 352dc5a01f Workload version: 8.0.300-manifests.113cb230 MSBuild version: 17.10.4+10fbfbf2e

Runtime Environment: OS Name: Windows OS Version: 10.0.22621 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\8.0.304\

.NET workloads installed: [aspire] Installation Source: VS 17.10.35201.131 Manifest Version: 8.1.0/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.1.0\WorkloadManifest.json Install Type: FileBased

Host: Version: 8.0.8 Architecture: x64 Commit: 08338fcaa5

.NET SDKs installed: 8.0.304 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 6.0.33 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.33 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 6.0.33 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found: x86 [C:\Program Files (x86)\dotnet]

global.json file: Not found

github-actions[bot] commented 4 weeks ago

Thank you for your feedback. Tagging and routing to the team member best able to assist.

jsquire commented 4 weeks ago

Hi @dmi-harlow. Thank you for reaching out and we regret that you're experiencing difficulties. The results of document analysis are provided exclusively by the Azure Document Intelligence service, which the Azure SDK client has no insight into nor influence over.

Unfortunately, the maintainers of the Azure SDK cannot assist with this issue. Because the Azure services are not open source and maintained on GitHub, we're unable to transfer this on your behalf. To ensure that the Document Itelligence service team has visibility and can help, your best path forward for would be to open an Azure support request or inquire on the Microsoft Q&A site.

I'm going to close this out; if I've misunderstood what you're describing, please let us know in a comment and we'd be happy to assist as we're able.

dmi-harlow commented 4 weeks ago

Hi @jsquire. Thank you for your prompt response. However, I do believe you have misunderstood my report. You said

The results of document analysis are provided exclusively by the Azure Document Intelligence service, which the Azure SDK client has no insight into nor influence over.

However, in my report, I described that the barcodes can be correctly read using a different SDK pointing to the same Azure Document Intelligence Service resource. This indicates that the problem lies not with the Document Intelligence Service, but with the SDK being used to access it. To use an analogy, if you fill up two cars from the same gas pump and one car drives fine and the other doesn't, you can't blame the gas.

dmi-harlow commented 4 weeks ago

To remove any concerns that Document Intelligence Studio might be doing some magic, here is sample code using the Azure.AI.FormRecognizer SDK:

using Azure;
using Azure.AI.FormRecognizer.DocumentAnalysis;
using Xunit;

string endpoint = "YOUR_FORM_RECOGNIZER_ENDPOINT";
string apiKey = "YOUR_FORM_RECOGNIZER_KEY";
string pdfFilePath = @"barcode-issue-sample.pdf";

var client = new DocumentAnalysisClient(new Uri(endpoint), new AzureKeyCredential(apiKey));
using Stream pdfStream = File.OpenRead(pdfFilePath);
var analyzeDocumentOptions = new AnalyzeDocumentOptions();
analyzeDocumentOptions.Features.Add(DocumentAnalysisFeature.Barcodes);
AnalyzeDocumentOperation operation = await client.AnalyzeDocumentAsync(WaitUntil.Completed, "prebuilt-read", pdfStream, options: analyzeDocumentOptions);
AnalyzeResult result = operation.Value;

Assert.NotEqual(0, result.Pages[0].Barcodes.Count); // Pass
Assert.Equal(DocumentBarcodeKind.Code128, result.Pages[0].Barcodes[0].Kind); // Pass
Assert.Equal("_P_BAYSTATE_42085_", result.Pages[0].Barcodes[0].Value); // Pass

Please take note that the Fail result of the sample code using the Azure.AI.DocumentIntelligence SDK was pointing to the same Azure Document Intelligence resource as the sample code using the Azure.AI.FormRecognizer SDK that returned Pass results.

dmi-harlow commented 4 weeks ago

Hi @jsquire. Re-reading your comment it seemed like you were hinting that the Azure SDK is little more than a thin wrapper around the Document Intelligence REST API. I took a quick look around the SDK source code and confirmed that is the case. Combining that realization with my own comment about the possibility that Document Intelligence Studio might be doing some magic, I also came to realize that it actually is doing something unexpected.

The Document Intelligence Studio allows you to select "2024-07-31 Preview" REST API version, however, the sample code it shows for C# is using the Azure.AI.FormRecognizer SDK which only supports up to API version "2023-07-31" (https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/formrecognizer/Azure.AI.FormRecognizer#getting-started).

So it looks like what might be happening is that the old SDK is working because it is using an old REST API version. And the new SDK is not working (for my use case) because the new REST API version is not working.

So, given that this is a preview build, I'm not sure submitting a support ticket is going to accomplish anything. I was just hoping to let the dev team know about this so they were aware of it. I am not planning to use a Preview API in production anyway. I just hope they fix this issue before the old API version goes out of support.