RecognizeAsync() публичный Метод

public RecognizeAsync ( [ strokeCollection, [ recognitionTarget ) : IAsyncOperation>
strokeCollection [
recognitionTarget [
Результат IAsyncOperation>
Пример #1
0
        private async void Recognize(object sender, EventArgs e)
        {
            if (Ink != null)
            {
                string str = string.Empty;
                IReadOnlyList<InkStroke> currentStrokes = Ink.InkPresenter.StrokeContainer.GetStrokes();
                if (currentStrokes.Count > 0)
                {
                    try
                    {
                        var inkRecognizerContainer = new InkRecognizerContainer();
                        var recognitionResults = await inkRecognizerContainer.RecognizeAsync(Ink.InkPresenter.StrokeContainer, InkRecognitionTarget.All);

                        if (recognitionResults.Count > 0)
                            foreach (var r in recognitionResults)
                                str += r.GetTextCandidates()[0];
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                }

                if (_vm != null)
                    _vm.RecognizeResult(str);
            }
        }
Пример #2
0
        private async void RecognizeButton_Click(object sender, RoutedEventArgs e)
        {
            var inkRecognizer = new InkRecognizerContainer();
            if (null != inkRecognizer)
            {
                var recognitionResults = await inkRecognizer.RecognizeAsync(this.InkCanvas.InkPresenter.StrokeContainer, InkRecognitionTarget.All);
                string recognizedText = string.Join(" ", recognitionResults.Select(i => i.GetTextCandidates()[0]));

                var messageDialog = new MessageDialog(recognizedText);
                await messageDialog.ShowAsync();
            }
        }
Пример #3
0
 public static async Task<string> Recognize(this InkCanvas inkCanvas)
 {
     var strokes = inkCanvas.InkPresenter.StrokeContainer;
     if (strokes.GetStrokes().Any())
     {
         var recognizer = new InkRecognizerContainer();
         var results = await recognizer.RecognizeAsync(strokes, InkRecognitionTarget.All);
         var candidates = results.Select(x => x.GetTextCandidates().First());
         return string.Join(" ", candidates);
     }
     else
     {
         return string.Empty;
     }
 }
Пример #4
0
        private async void reco_Click(object sender, RoutedEventArgs e)
        {
            if (ink.InkPresenter.StrokeContainer.GetStrokes().Count > 0)
            {
                var recognizer = new InkRecognizerContainer();
                var recognitionResults = await recognizer.RecognizeAsync(ink.InkPresenter.StrokeContainer, InkRecognitionTarget.All);

                string result = "";
                //justACanvas.Children.Clear();

                if (recognitionResults.Count > 0)
                {
                    foreach (var r in recognitionResults)
                    {
                        var candidates = r.GetTextCandidates();
                        result += " " + candidates[0];
                        
                    }
                }
                else
                    result = "NO TEXT RECOGNIZED!";

                RecoResult.Text = result;
            }
        }
Пример #5
0
        private async Task RecognizeInkerText()
        {
            System.Diagnostics.Debug.WriteLine("RecognizeInkerText");
            try
            {
                var inkRecognizer = new InkRecognizerContainer();
                var recognitionResults = await inkRecognizer.RecognizeAsync(inker.InkPresenter.StrokeContainer, InkRecognitionTarget.All);

                List<TextBox> textBoxes = new List<TextBox>();

                string value = string.Empty; 

                foreach (var result in recognitionResults)
                {
                    if (TargetTextControl == null)
                    {
                        Point p = new Point(result.BoundingRect.X, result.BoundingRect.Y);
                        Size s = new Size(result.BoundingRect.Width, result.BoundingRect.Height);
                        Rect r = new Rect(p, s);
                        var elements = VisualTreeHelper.FindElementsInHostCoordinates(r, contentPresenter);

                        TextBox box = elements.Where(el => el is TextBox && (el as TextBox).IsEnabled).FirstOrDefault() as TextBox;
                        if (box != null)
                        {
                            if (!textBoxes.Contains(box))
                            {
                                textBoxes.Add(box);
                                box.Text = "";
                            }
                            if (string.IsNullOrEmpty(box.Text) == false)
                                box.Text += " ";
                            box.Text += result.GetTextCandidates().FirstOrDefault().Trim();
                        }
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(value) == false)
                            value += " ";
                        value += result.GetTextCandidates().FirstOrDefault().Trim();
                    }
                        
                }

                if (TargetTextControl != null)
                {
                    var type = TargetTextControl.GetType();
                    PropertyInfo pInfo = type.GetProperty(TEXT_PROPERTY_NAME);
                    pInfo.SetValue(TargetTextControl, value);
                }

                inker.InkPresenter.StrokeContainer.Clear();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
        }
        private async Task RecognizeInkerText()
        {
            var inkRecognizer = new InkRecognizerContainer();
            var recognitionResults = await inkRecognizer.RecognizeAsync(Inker.InkPresenter.StrokeContainer, InkRecognitionTarget.All);

            List<TextBox> boxes = new List<TextBox>();

            foreach (var result in recognitionResults)
            {
                List<UIElement> elements = new List<UIElement>(
                    VisualTreeHelper.FindElementsInHostCoordinates(
                        new Rect(new Point(result.BoundingRect.X, result.BoundingRect.Y),
                        new Size(result.BoundingRect.Width, result.BoundingRect.Height)),
                    this));

                TextBox box = elements.Where(el => el is TextBox && (el as TextBox).IsEnabled).FirstOrDefault() as TextBox;

                if (box != null)
                {
                    if (!boxes.Contains(box))
                    {
                        boxes.Add(box);
                        box.Text = "";
                    }
                    box.Text +=  result.GetTextCandidates().FirstOrDefault().Trim();
                }
            }

            Inker.InkPresenter.StrokeContainer.Clear();
        }
Пример #7
0
        private async void Reco_Click(object sender, RoutedEventArgs e)
        {
            if (inkCanvas.InkPresenter.StrokeContainer.GetStrokes().Count > 0)
            {
                var recognizer = new InkRecognizerContainer();
                var recognitionResults = await recognizer.RecognizeAsync(inkCanvas.InkPresenter.StrokeContainer, InkRecognitionTarget.All);

                string result = "";
                //justACanvas.Children.Clear();

                if (recognitionResults.Count > 0)
                {
                    foreach (var r in recognitionResults)
                    {
                        var candidates = r.GetTextCandidates();
                        result += " " + candidates[0];

                        //var rect = r.BoundingRect;
                        //var text = new TextBlock();
                        //text.Text = candidates[0];
                        //justACanvas.Children.Add(text);
                        //Canvas.SetTop(text, rect.Bottom + 5);
                        //Canvas.SetLeft(text, rect.Left);
                    }
                }
                else
                    result = "NO TEXT RECOGNIZED!";

                recoResult.Text = result;
            }
        }