Exemplo n.º 1
0
        public string ImageOcrToText(string imagePath)
        {
            string apiValue = _keys[Random.Next(_keys.Length)];

            Configuration.Default.AddApiKey("Apikey", apiValue);
            var imageFile = new System.IO.FileStream(imagePath, System.IO.FileMode.Open);

            try
            {
                // Converts an uploaded image in common formats such as JPEG, PNG into text via Optical Character Recognition.
                ImageToTextResponse result = ApiInstance.ImageOcrPost(imageFile, "ENG");
                Debug.WriteLine(result);
                return(result?.TextResult);
            }
            catch (Exception e)
            {
                Debug.Print("Exception when calling ImageOcrApi.ImageOcrPost: " + e.Message);
                throw;
            }
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var response = new ImageToTextResponse();

            Configuration.Default.AddApiKey("Apikey", "c3543902-1862-498b-ba4a-256688c39435");
            var apiInstance = new ImageOcrApi();
            var imageFile   = new System.IO.FileStream(@"C:\Temp\aratest.tif", System.IO.FileMode.Open); // System.IO.Stream | Image file to perform OCR on.  Common file formats such as PNG, JPEG are supported.

            try
            {
                // Converts an uploaded image in common formats such as JPEG, PNG into text via Optical Character Recognition.
                response = apiInstance.ImageOcrPost(imageFile, txtLanguage.Text, "none");
                Debug.Print(response.TextResult);

                txtResult.Text = response.TextResult;
            }
            catch
            {
                Debug.Print("Exception when calling ImageOcrApi.ImageOcrPost: ");
            }
        }