Exemplo n.º 1
0
Arquivo: Ocr.cs Projeto: fraxedas/OCR
        public static async Task <string> GetTextAsync(Stream imageFilePath)
        {
            try
            {
                using (var client = new ComputerVisionClient(new ApiKeyServiceClientCredentials(SubscriptionKey))
                {
                    Endpoint = UriBase
                })
                {
                    var result =
                        await client.RecognizePrintedTextInStreamWithHttpMessagesAsync(true, imageFilePath);

                    return(result.Body.GetText());
                }
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }
Exemplo n.º 2
0
        private static async Task MakeApiRequest(string imageFilePath)
        {
            try
            {
                using (var client = new ComputerVisionClient(new ApiKeyServiceClientCredentials(subscriptionKey))
                {
                    Endpoint = uriBase
                })
                {
                    var result =
                        await client.RecognizePrintedTextInStreamWithHttpMessagesAsync(true,
                                                                                       File.OpenRead(imageFilePath));

                    Console.WriteLine(result.Body.GetText());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("\n" + e.Message);
            }
        }