Esempio n. 1
0
        private static async Task GetTextAsync(VisionServiceClient client,
                                               string path)
        {
            using (Stream imageStream = File.OpenRead(path))
            {
                var t = client.CreateTextRecognitionOperationAsync(imageStream,
                                                                   TextRecognitionMode.Printed);
                if (t.Result != null)
                {
                    var result = await client.GetTextRecognitionOperationResultAsync(t.Result);

                    int i        = 0;
                    int maxRetry = 60;

                    while ((result.Status == TextRecognitionOperationStatus.Running || result.Status == TextRecognitionOperationStatus.NotStarted) &&
                           i++ < maxRetry)
                    {
                        Console.WriteLine("Server status: {0}, waiting {1} seconds...",
                                          result.Status,
                                          i);
                        await Task.Delay(1000);

                        result = await client.GetTextRecognitionOperationResultAsync(t.Result);
                    }

                    StringBuilder builder = new StringBuilder();
                    foreach (var line in result.RecognitionResult.Lines)
                    {
                        Console.WriteLine(line.Text);
                    }
                }
            }
        }