Ejemplo n.º 1
0
        /*
         *	EXTRACT TEXT - URL IMAGE
         */
        public async Task ExtractTextFromURL(string url)
        {
            const int numberOfCharsInOperationId = 36;

            Console.WriteLine("----------------------------------------------------------");
            Console.WriteLine("EXTRACT TEXT - URL");
            Console.WriteLine();

            Console.WriteLine($"Extracting text from url {url}...");
            Console.WriteLine();

            var headers = await _client.BatchReadFileWithHttpMessagesAsync(url);

            string operationLocation = headers.Headers.OperationLocation;

            // Retrieve the URI where the recognized text will be stored from the Operation-Location header.
            // We only need the ID and not the full URL

            string operationId = operationLocation.Substring(operationLocation.Length - numberOfCharsInOperationId);

            // Extract the text
            // Delay is between iterations and tries a maximum of 10 times.
            int i          = 0;
            int maxRetries = 10;
            ReadOperationResult results;

            do
            {
                results = await _client.GetReadOperationResultAsync(operationId);

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

            // Display the found text.
            Console.WriteLine();
            var recognitionResults = results.RecognitionResults;

            foreach (TextRecognitionResult result in recognitionResults)
            {
                foreach (var line in result.Lines)
                {
                    if (_reNumberPlate.IsMatch(line.Text))
                    {
                        Console.WriteLine(line.Text);
                    }
                }
            }
            Console.WriteLine();
        }
Ejemplo n.º 2
0
        public async Task <string> ExtractLocalPrintedTextAsync(string photoUrl)
        {
            try
            {
                // TextRecognitionMode.Printed or TextRecognitionMode.Handwritten
                var result = await _computerVision.BatchReadFileWithHttpMessagesAsync(photoUrl, TextRecognitionMode.Printed);

                var res = await GetTextAsync(_computerVision, result.Headers.OperationLocation);

                return(res);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }