locked
InkManager.RecognizeAsync

    Question

  • I'm having trouble implementing handwriting recognition.  Actually everything works correctly the first time I try to recognize something, the trouble starts after I clear the canvas and the user writes something new.  The canvas clears okay and based on what GetStrokes() tells me it seems the new strokes are recorded properly.  However, when I call RecognizeAsync() on the second entry I consistently get the error:

    Value does not fall within the expected range.

    I've been through all the sample code and everything appears to be the same.  All of the pointer events seem to work fine.

    These are the two functions I'm focusing on - the recognition and the subsequent clearing of the canvas, which then leads to recognition again:

    private async void btnRecognize_Tapped(object sender, TappedRoutedEventArgs e)
    {
                try
                {
                   // for debug only                
                  IReadOnlyList<InkStroke> strokes = im.GetStrokes(); 
    
                    IReadOnlyList<InkRecognitionResult> irr = await im.RecognizeAsync(InkRecognitionTarget.All);
                    im.UpdateRecognitionResults(irr);
    
                    if (irr.Count > 0)
                    {
                        IReadOnlyList<string> candidates = irr[0].GetTextCandidates();
    
                        results = new List<Result>();
                        foreach (string c in candidates)
                        {
                            Result r = new Result();
                            r.text = c;
                            results.Add(r);
                        }
                    }
                }
                catch (Exception exc)
                {
                    App.LogException("Flashcard.btnRecognize_Tapped", exc.Message);
                }
    
                clearInk();
            }

    private void clearInk()
    {
         try
         { 
              im.Mode = InkManipulationMode.Erasing;
    
              IReadOnlyList<InkStroke> strokes = im.GetStrokes();
    
              foreach (InkStroke stroke in strokes)
                   stroke.Selected = true;
    
              im.DeleteSelected();
    
              inkCanvas.Children.Clear();
    
              im.Mode = InkManipulationMode.Inking;
          }
          catch(Exception exc)
          {
                App.LogException(exc.Message);
          }
    }

    Thursday, January 08, 2015 9:29 PM

All replies