public async Task RecognizeContentFromFile()
        {
            string endpoint = TestEnvironment.Endpoint;
            string apiKey   = TestEnvironment.ApiKey;

            FormRecognizerClient client = new FormRecognizerClient(new Uri(endpoint), new AzureKeyCredential(apiKey));

            string invoiceFilePath = FormRecognizerTestEnvironment.CreatePath("Invoice_1.pdf");

            using (FileStream stream = new FileStream(invoiceFilePath, FileMode.Open))
            {
                FormPageCollection formPages = await client.StartRecognizeContent(stream).WaitForCompletionAsync();

                foreach (FormPage page in formPages)
                {
                    Console.WriteLine($"Form Page {page.PageNumber} has {page.Lines.Count} lines.");

                    for (int i = 0; i < page.Lines.Count; i++)
                    {
                        FormLine line = page.Lines[i];
                        Console.WriteLine($"    Line {i} has {line.Words.Count} word{(line.Words.Count > 1 ? "s" : "")}, and text: '{line.Text}'.");
                    }

                    for (int i = 0; i < page.Tables.Count; i++)
                    {
                        FormTable table = page.Tables[i];
                        Console.WriteLine($"Table {i} has {table.RowCount} rows and {table.ColumnCount} columns.");
                        foreach (FormTableCell cell in table.Cells)
                        {
                            Console.WriteLine($"    Cell ({cell.RowIndex}, {cell.ColumnIndex}) contains text: '{cell.Text}'.");
                        }
                    }
                }
            }
        }
        public async Task BoundingBoxSample()
        {
            string endpoint = TestEnvironment.Endpoint;
            string apiKey   = TestEnvironment.ApiKey;

            FormRecognizerClient client = new FormRecognizerClient(new Uri(endpoint), new AzureKeyCredential(apiKey));

            string invoiceFilePath = FormRecognizerTestEnvironment.CreatePath("Invoice_1.pdf");

            using (FileStream stream = new FileStream(invoiceFilePath, FileMode.Open))
            {
                FormPageCollection formPages = await client.StartRecognizeContent(stream).WaitForCompletionAsync();

                foreach (FormPage page in formPages)
                {
                    Console.WriteLine($"Form Page {page.PageNumber} has {page.Lines.Count} lines.");

                    for (int i = 0; i < page.Lines.Count; i++)
                    {
                        FormLine line = page.Lines[i];
                        Console.WriteLine($"    Line {i} with text: '{line.Text}'.");

                        Console.WriteLine("        Its bounding box is:");
                        Console.WriteLine($"        Upper left => X: {line.BoundingBox[0].X}, Y= {line.BoundingBox[0].Y}");
                        Console.WriteLine($"        Upper right => X: {line.BoundingBox[1].X}, Y= {line.BoundingBox[1].Y}");
                        Console.WriteLine($"        Lower right => X: {line.BoundingBox[2].X}, Y= {line.BoundingBox[2].Y}");
                        Console.WriteLine($"        Lower left => X: {line.BoundingBox[3].X}, Y= {line.BoundingBox[3].Y}");
                    }
                }
            }
        }
Beispiel #3
0
        static async Task FormsExtraction(string imgPath)
        {
            // based on https://docs.microsoft.com/en-us/azure/cognitive-services/form-recognizer/quickstarts/client-library c# version

            Console.Write("Extracting forms from " + imgPath + " ...");
            using (var stImg = new FileStream(imgPath, FileMode.Open))
            {
                var recognizerClient = new FormRecognizerClient(
                    new Uri(DemoSettings.csFormsRecognizerEnpoint),
                    new Azure.AzureKeyCredential(DemoSettings.csFormsRecognizerKey));

                var imgForms = await recognizerClient.StartRecognizeContent(stImg /*, new RecognizeOptions() { IncludeTextContent = true }*/).WaitForCompletionAsync();

                if (imgForms.Value != null)
                {
                    PrintFormsExtractionResult(imgForms.Value);
                }
            }
        }
Beispiel #4
0
        public async Task RecognizeFormContentFromFile()
        {
            string endpoint = TestEnvironment.Endpoint;
            string apiKey   = TestEnvironment.ApiKey;

            var credential = new AzureKeyCredential(apiKey);
            var client     = new FormRecognizerClient(new Uri(endpoint), credential);

            string invoiceFilePath = FormRecognizerTestEnvironment.CreatePath("Invoice_1.pdf");

            #region Snippet:FormRecognizerRecognizeFormContentFromFile
            using (FileStream stream = new FileStream(invoiceFilePath, FileMode.Open))
            {
                FormPageCollection formPages = await client.StartRecognizeContent(stream).WaitForCompletionAsync();

                /*
                 *
                 */
            }
            #endregion
        }
 public async Task <FormPageCollection> AnalyzeFormFromStream(Stream form)
 => await client.StartRecognizeContent(form).WaitForCompletionAsync();
Beispiel #6
0
        public async Task <FormPageCollection> AnalyzeFormFromStream(Stream form)
        {
            FormPageCollection collection = await _frClient.StartRecognizeContent(form).WaitForCompletionAsync();

            return(collection);
        }