I'm trying to follow this tutorial to specify the model some fileds I would like to extract. But this page seems completely outdated, since AnalyzeDocumentAsync doesn't expect any parameter like queryFields.
This is my current code:
var credential = new AzureKeyCredential(endpointAPI.APIKey);
var client = new DocumentAnalysisClient(new Uri(endpointAPI.Endpoint), credential);
for (int i = 0; i < Images.Count; i++)
{
using (MemoryStream ms = new MemoryStream(Images[i]))
{
//I want to specify somehow which Fields should be extracted
AnalyzeDocumentOperation operation = await client.AnalyzeDocumentAsync(WaitUntil.Completed, "prebuilt-receipt", ms);
AnalyzeResult receipts = operation.Value;
foreach (AnalyzedDocument receipt in receipts.Documents)
{ ... }
}
}
I'm using Azure.AI.FormRecognizer 4.1.0 on .NET Standard 2.0
Gather labeled data (documents with the fields you want to extract) and train a custom model using the Form Recognizer service. You can do this through the Azure Portal or programmatically using the SDK.
Once the custom model is trained, you can use it to analyze documents and extract the specified fields.
Using the Azure Form Recognizer SDK:
var credential = new AzureKeyCredential(endpointAPI.APIKey);
var client = new DocumentModelAdministrationClient(new Uri(endpointAPI.Endpoint), credential);
// Assuming you've already trained a custom model with the ID "your_custom_model_id"
string modelId = "your_custom_model_id";
for (int i = 0; i < Images.Count; i++)
{
using (MemoryStream ms = new MemoryStream(Images[i]))
{
AnalyzeDocumentOperation operation = await client.StartAnalyzeDocumentAsync(modelId, ms);
await operation.WaitForCompletionAsync();
AnalyzeResult result = await operation.GetAnalyzeResultAsync();
foreach (var page in result.Pages)
{
foreach (var field in page.Fields)
{
// Access the extracted fields here
string fieldName = field.Key;
var fieldValue = field.Value;
// Handle the extracted fields accordingly
}
}
}
}
Result:
Document 1:
- Page 1:
- Field "Date": "2024-04-19"
- Field "Merchant": "ABC Store"
- Field "Total": "$50.00"
Document 2:
- Page 1:
- Field "Date": "2024-04-18"
- Field "Merchant": "XYZ Market"
- Field "Total": "$35.20"
Using Azure portal: