2017-03-14 30 views
0

私はXamarin PLCで画像を取り込むためにXamarin Media Pluginを使用し、テキスト認識にはProjectOxford OCRを使用しています。 OCR APIでは、検出されたテキスト行のパラメータを知ることができます: width、height、top、left。 それでは、どのようにして、deteted textに新しいテキスト(例えば別の言語で)の長方形を描画できますか?ありがとう!OCRテキストで検出された矩形を描画する方法

ソースコード:


     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

ここで素晴らしい解決策が見つかりました(ロシア語):https://metanit.com/sharp/xamarin/3.5.php – dimaKush

答えて

0

プロジェクトオックスフォードのAPIは、単語がJSON形式のリストとして座標を返します。このデータを使用してボックスを描画することができます。

+0

thats correct、thanks。問題は、Xamarin PCLで新しいテキストの長方形のようなものを描画する方法です。 – dimaKush

関連する問題