2017-03-14 4 views
0

Ich verwende Xamarin Media Plugin in Xamarin PLC für die Auswahl Bild und ProjectOxford OCR für die Texterkennung. OCR API ermöglicht mir, diese Parameter der erkannten Textzeile zu kennen: Breite, Höhe, oben, links. Also, wie kann ich ein Rechteck mit neuem Text (in einer anderen Sprache zum Beispiel) auf erkanntem Text zeichnen? Vielen Dank!Wie zeichne Rechteck auf erkannte durch OCR-Text

Quellcode:


     public partial class OcrRecognitionPage : ContentPage 
     { 
     public Exception Error 
     { 
      get; 
      private set; 
     } 

     private readonly VisionServiceClient visionClient; 

     int Top = 0; 
     int Left = 0; 
     int width = 0; 
     int height = 0; 

     public OcrRecognitionPage() 
     { 
      this.Error = null; 
      InitializeComponent(); 
      this.visionClient = new VisionServiceClient("Enter your code"); 

     } 

     private async Task AnalyzePictureAsync(Stream inputFile) 
     { 
      if (!CrossConnectivity.Current.IsConnected) 
      { 
       await DisplayAlert("Network error", "Please check your network connection and retry.", "OK"); 
       return null; 
      } 

      OcrResults ocrResult = await visionClient.RecognizeTextAsync(inputFile); 
      return ocrResult; 
     } 

     private async void TakePictureButton_Clicked(object sender, EventArgs e) 
     { 
      try 
      { 
       await CrossMedia.Current.Initialize(); 

       if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported) 
       { 
        await DisplayAlert("No Camera", "No camera available.", "OK"); 
        return; 
       } 
       var file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions 
       { 
        SaveToAlbum = false, 
        Name = "test.jpg", 
        CompressionQuality = 75 

       }); 
       if (file == null) 
        return; 
       Image1.Source = ImageSource.FromStream(() => file.GetStream()); 
       var ocrResult = await AnalyzePictureAsync(file.GetStream()); 

       this.BindingContext = null; 
       this.BindingContext = ocrResult; 
       sourceLanguage = ocrResult.Language; 

       PopulateUIWithRegions(ocrResult); 
      } 
      catch (Exception ex) 
      { 
       this.Error = ex; 
      } 
     } 
     private void PopulateUIWithRegions(OcrResults ocrResult) 
     { 
       //Iterate the regions 
       foreach (var region in ocrResult.Regions) 
      { 
       //Iterate lines per region 
       foreach (var line in region.Lines) 
       { 
       // For each line, add a panel to present words horizontally 
        var lineStack = new StackLayout 
        { Orientation = StackOrientation.Horizontal }; 

        //Iterate words per line and add the word 
        //to the StackLayout 
        foreach (var word in line.Words) 
        { 
         var textLabel = new Label 
         { 
          TextColor = Xamarin.Forms.Color.Black, 
          Text = word.Text, 

         }; 

         lineStack.Children.Add(textLabel); 
        } 

        height = line.Rectangle.Height; 
        width = line.Rectangle.Width; 
        Left = line.Rectangle.Left; 
        Top = line.Rectangle.Top; 
        // Here i get coordinates. How can i use it to wraw rectangle onto it with another text?  
       }  
      } 
     } 
+0

Gefunden großartige Lösung hier (auf Russisch): https://metanit.com/sharp/xamarin/3.5.php – dimaKush

Antwort

0

Das Projekt Oxford API, das Wort gibt Koordinaten als JSON formatierte Liste. Sie können diese Daten verwenden, um die Boxen zu zeichnen.

+0

das ist richtig, danke. Die Frage ist, wie man in Xamarin PCL etwas wie ein Rechteck mit neuem Text darauf zeichnet. – dimaKush

Verwandte Themen