question

VamikaSatrasala-1151 avatar image
0 Votes"
VamikaSatrasala-1151 asked romungi-MSFT commented

Deployment error while trying to perform OCR [Azure] after capturing image to extract text

I am trying to perform OCR on image captured on mobile camera and photos from user gallery to extract text but I keep getting deployment errors such as "system host not known"


async void UploadAndDetectButton_Clicked(System.Object sender, System.EventArgs e)
{

         var result = await MediaPicker.PickPhotoAsync(new MediaPickerOptions
         {
             Title = "Please pick a photo"
         });
         if (result != null)
         {
             var stream = await result.OpenReadAsync();

             MyImage.Source = ImageSource.FromStream(() => stream);
         }
     }


     async void CaptureButton_Clicked(System.Object sender, System.EventArgs e)
      {
       var result = await MediaPicker.CapturePhotoAsync();
      if (result != null)
     {
       var stream = await result.OpenReadAsync();

             var client = new ComputerVisionClient(new ApiKeyServiceClientCredentials(subscriptionKey)) { Endpoint = endpoint };


             var ocrResult = await client.ReadInStreamAsync(stream);

             var operationLocation = ocrResult.OperationLocation;
             const int numberOfCharsInOperationId = 36;
             string operationId = operationLocation.Substring(operationLocation.Length - numberOfCharsInOperationId);
             // Extract the text
             ReadOperationResult results;
             do
             {
                 results = await client.GetReadResultAsync(Guid.Parse(operationId));
             }
             while ((results.Status == OperationStatusCodes.Running ||
             results.Status == OperationStatusCodes.NotStarted));
             // Display the text.
             var textResults = results.AnalyzeResult.ReadResults;
             foreach (ReadResult page in textResults)
             {
                 string labelValue = "";
                 foreach (Microsoft.Azure.CognitiveServices.Vision.ComputerVision.Models.Line line in page.Lines)
                 {
                     labelValue += page.Lines;
                 }


                 Result1.Text = labelValue;
                 OCRText = labelValue;
             }

             await TextToSpeech.SpeakAsync(OCRText, new SpeechOptions
             {
                 Pitch = 0.5f
             });

             MyImage.Source = ImageSource.FromStream(() => stream);
     }
     }
       
 }

I would like to know if there is something wrong or something I need to add for the code to perform ocr and also text-to-speech later on

azure-computer-vision
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

romungi-MSFT avatar image
0 Votes"
romungi-MSFT answered romungi-MSFT commented

@VamikaSatrasala-1151 The most likely reason for the error could be the client is not initiated correctly with the right endpoint and subscription keys. Could you try something like below?

             ComputerVisionClient computerVision = new ComputerVisionClient(  
                 new ApiKeyServiceClientCredentials(subscriptionKey),  
                 new System.Net.Http.DelegatingHandler[] { });  
      
             // You must use the same region as you used to get your subscription  
             // keys. For example, if you got your subscription keys from westus,  
             // replace "westcentralus" with "westus".  
             //  
             // Free trial subscription keys are generated in the "westus"  
             // region. If you use a free trial subscription key, you shouldn't  
             // need to change the region.  
      
             // Specify the Azure region  
             computerVision.Endpoint = "https://centralindia.api.cognitive.microsoft.com";  


If an answer is helpful, please click on 130616-image.png or upvote 130671-image.png which might help other community members reading this thread.


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I have tried what you said above yet it still keeps crashing stating; "System.Net.Http.HttpRequestException: No such host is known"
I have connected my phone to the internet so it shouldn't be that problem!

0 Votes 0 ·

@VamikaSatrasala-1151 I would recommend to debug by calling your endpoint directly through REST API before using it in the solution? You can check if the right region is used to call with the keys.
If the endpoint is correct, then you can run the solution in debug mode with more logging to check if the same error is seen. I assume the host mentioned in the error is the endpoint or your resource with the right keys, which is open to public internet.
If it is unable to connect in this mode then there should be some issue in the app that is preventing the same. I hope the logs could provide more info.


0 Votes 0 ·