MicrosoftDocs / azure-docs

Open source documentation of Microsoft Azure
https://docs.microsoft.com/azure
Creative Commons Attribution 4.0 International
10.28k stars 21.47k forks source link

No barcode information returned when using Form Recognizer #111998

Closed EcoleKeine closed 1 year ago

EcoleKeine commented 1 year ago

I tried to extract barcode information from a code 39 barcode image using the Form Recognizer, but no barcode information was returned.

image is https://learn.microsoft.com/en-us/azure/applied-ai-services/form-recognizer/media/barcodes/code-39.png?view=form-recog-3.0.0 without bottom characters

model is prebuilt-read/prebuilt-layout free plan F0

using Azure.AI.FormRecognizer.DocumentAnalysis;
DocumentAnalysisClient client = new DocumentAnalysisClient(new Uri(endpoint), credential);
AnalyzeDocumentOperation operation = await client.AnalyzeDocumentAsync(WaitUntil.Completed, modelType, stream);

there are no barcodes collection in return:

{
    "modelId": "prebuilt-read",
    "content": "",
    "pages": [
        {
            "unit": 0,
            "pageNumber": 1,
            "angle": 0,
            "width": 420,
            "height": 78,
            "spans": [
                {
                    "index": 0,
                    "length": 0
                }
            ],
            "words": [],
            "selectionMarks": [],
            "lines": []
        }
    ],
    "paragraphs": [],
    "tables": [],
    "keyValuePairs": [],
    "styles": [],
    "languages": [],
    "documents": []
}

Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

EcoleKeine commented 1 year ago

find the problem: The latest release version of Azure.AI.FormRecognizer is 4.0.0, result class DocumentPage no contain barcodes. this should be documented.

But change to version 4.1.0-beta.1, I get 404 error.

RamanathanChinnappan-MSFT commented 1 year ago

@EcoleKeine

I've delegated this to @laujan , a content author, to review and share their valuable insights.

laujan commented 1 year ago

Hi @EcoleKeine, Thank you for your feedback. The barcode extraction feature is available in the latest REST API and SDK versions:

We've updated the documentation.

It looks as if you were using C#. Here is a code snippet that is supported by the latest version:

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

string endpoint = "your-endpoint";
string key = "your-api-key";
AzureKeyCredential credential = new AzureKeyCredential(key);
DocumentAnalysisClient client = new DocumentAnalysisClient(new Uri(endpoint), credential);

Uri barcodeUri = new Uri("https://raw.githubusercontent.com/Azure-Samples/cognitive-services-REST-api-samples/master/curl/form-recognizer/barcodes.png");

AnalyzeDocumentOperation operation = await client.AnalyzeDocumentFromUriAsync(WaitUntil.Completed, "prebuilt-read", barcodeUri);
AnalyzeResult result = operation.Value;

foreach(DocumentPage page in result.Pages) {
  for (int i = 0; i < page.Barcodes.Count; i++) {
    DocumentBarcode barcode = page.Barcodes[i];
    Console.WriteLine($"Document barcodes {i} is Kind: {barcode.Kind},Value: {barcode.Value}, Confidence: {barcode.Confidence} ");
  }

}

For more information on barcodes, see DocumentPage.Barcodes Property

Thanks again!