Skip to content

Instantly share code, notes, and snippets.

@bogdanbujdea
Created March 19, 2021 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bogdanbujdea/d4a09d78615f785b1332ddf6db65028f to your computer and use it in GitHub Desktop.
Save bogdanbujdea/d4a09d78615f785b1332ddf6db65028f to your computer and use it in GitHub Desktop.
Retrieve fields from ID with Form Recognizer
static async Task Main(string[] args)
{
var resultUrl = await StartAnalyzingImage(); // defined here https://gist.github.com/thewindev/a3a06af46693b890e968fbf810d2b50d
IdentificationResult result;
do
{
await Task.Delay(1000); // wait 1 second before checking, otherwise the API will return 429
var json = await _client.GetStringAsync(resultUrl);
result = JsonConvert.DeserializeObject<IdentificationResult>(json);
} while (result?.Status != "succeeded");
var documentResults = result.AnalyzeResult.DocumentResults;
if (documentResults != null && documentResults.Length != 0)
{
foreach (var documentResult in documentResults)
{
Console.WriteLine($"First name: {documentResult.Fields.FirstName}, confidence: {documentResult.Fields.FirstName.Confidence}");
Console.WriteLine($"Last name: {documentResult.Fields.FirstName}, confidence: {documentResult.Fields.LastName.Confidence}");
Console.WriteLine($"Address: {documentResult.Fields.Address}, confidence: {documentResult.Fields.Address.Confidence}");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment