2017-03-14 1 views
0

Xamarin PLC에서 이미지를 가져 오는 데 Xamarin Media Plugin을 사용하고 텍스트 인식을 위해 ProjectOxford OCR을 사용하고 있습니다. OCR API를 통해 감지 된 텍스트 줄의 매개 변수를 알 수 있습니다 : 너비, 높이, 위쪽, 왼쪽. 그럼, 어떻게 deteted 텍스트에 (예를 들어, 다른 언어로) 새로운 텍스트로 사각형을 그릴 수 있습니까? 감사!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

관련 문제