Metodo RecognizerContext.BackgroundRecognize
Aggiornamento: novembre 2007
Fa in modo che l'oggetto Recognizer riconosca l'insieme Strokes associato e generi un evento Recognition quando il riconoscimento è completo.
Spazio dei nomi: Microsoft.Ink
Assembly: Microsoft.Ink (in Microsoft.Ink.dll)
Sintassi
'Dichiarazione
Public Sub BackgroundRecognize
'Utilizzo
Dim instance As RecognizerContext
instance.BackgroundRecognize()
public void BackgroundRecognize()
public:
void BackgroundRecognize()
public void BackgroundRecognize()
public function BackgroundRecognize()
Note
Questo metodo specifica che il riconoscimento dell'input penna viene eseguito in modo asincrono. Per riconoscere l'input penna in modo sincrono, chiamare il metodo RecognizerContext.Recognize.
Questo metodo riconosce solo la stringa di risultato migliore. Questo metodo non crea oggetti RecognitionAlternate. Per eseguire il riconoscimento che crea un elenco di alternative disponibili, chiamare il metodo BackgroundRecognizeWithAlternates.
Se il sistema di riconoscimento non riconosce nessun dato, l'evento Recognition non viene generato.
Esempi
In questo esempio viene riconosciuto automaticamente ogni tratto eseguito in un oggetto InkOverlay e visualizzato il risultato del riconoscimento.
All'avvio dell'applicazione, viene creata un'istanza dell'oggetto RecognizerContext e vengono assegnati i gestori eventi.
' create a new RecognizerContext object
' the object's Strokes property is initialized to null
mRecognizerContext = New RecognizerContext()
' assign the Strokes property by creating a fresh Strokes collection
mRecognizerContext.Strokes = mInkOverlay.Ink.CreateStrokes()
' subscribe to the Strokes event. It is during this event
' that we can add strokes to the RecognizerContext
AddHandler mInkOverlay.Stroke, New InkCollectorStrokeEventHandler(AddressOf mInkOverlay_Stroke2)
' subscribe to the the Recognition event.
' This event is fired when background recognition is complete,
' and recognition results (without alternates) are available
AddHandler mRecognizerContext.Recognition, _
New RecognizerContextRecognitionEventHandler(AddressOf mRecognizerContext_Recognition)
// create a new RecognizerContext object
// the object's Strokes property is initialized to null
mRecognizerContext = new RecognizerContext();
// assign the Strokes property by creating a fresh Strokes collection
mRecognizerContext.Strokes = mInkOverlay.Ink.CreateStrokes();
// subscribe to the Strokes event. It is during this event
// that we can add strokes to the RecognizerContext
mInkOverlay.Stroke += new InkCollectorStrokeEventHandler(mInkOverlay_Stroke2);
// subscribe to the the Recognition event.
// This event is fired when background recognition is complete,
// and recognition results (without alternates) are available
mRecognizerContext.Recognition +=
new RecognizerContextRecognitionEventHandler(mRecognizerContext_Recognition);
Quando viene generato l'evento Stroke (in risposta al completamento di un tratto da parte dell'utente), il tratto appena creato viene aggiunto all'insieme Strokes dell'oggetto RecognizerContext e viene chiamato il metodo BackgroundRecognize.
Private Sub mInkOverlay_Stroke2(ByVal sender As Object, ByVal e As InkCollectorStrokeEventArgs)
' in case background recognition is still occurring, stop it
mRecognizerContext.StopBackgroundRecognition()
' add the stroke, and start recognition
mRecognizerContext.Strokes.Add(e.Stroke)
mRecognizerContext.BackgroundRecognize()
End Sub
private void mInkOverlay_Stroke2(object sender, InkCollectorStrokeEventArgs e)
{
// in case background recognition is still occurring, stop it
mRecognizerContext.StopBackgroundRecognition();
// add the stroke, and start recognition
mRecognizerContext.Strokes.Add(e.Stroke);
mRecognizerContext.BackgroundRecognize();
}
Al termine del riconoscimento in background, viene generato l'evento Recognition. Durante la gestione di questo evento, i risultati del riconoscimento vengono collocati in una casella di riepilogo.
' event fires when recognition results (without alternates) are ready
Private Sub mRecognizerContext_Recognition(ByVal sender As Object, _
ByVal e As RecognizerContextRecognitionEventArgs)
' when updating a control, must use Invoke() since controls are
' not thread safe and recognition occurs on a different thread
If Me.InvokeRequired Then
' recursively call this method via Invoke()
Me.Invoke( _
New RecognizerContextRecognitionEventHandler(AddressOf mRecognizerContext_Recognition), _
New Object() {sender, e} _
)
Return
End If
If RecognitionStatus.NoError = e.RecognitionStatus Then
listBoxRecognitionResults.Items.Add(e.Text)
End If
End Sub
// event fires when recognition results (without alternates) are ready
private void mRecognizerContext_Recognition(object sender, RecognizerContextRecognitionEventArgs e)
{
// when updating a control, must use Invoke() since controls are
// not thread safe and recognition occurs on a different thread
if (this.InvokeRequired)
{
// recursively call this method via Invoke()
this.Invoke(
new RecognizerContextRecognitionEventHandler(mRecognizerContext_Recognition),
new object[] { sender, e }
);
return;
}
if (RecognitionStatus.NoError == e.RecognitionStatus)
{
listBoxRecognitionResults.Items.Add(e.Text);
}
}
Piattaforme
Windows Vista
.NET Framework e .NET Compact Framework non supportano tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema di .NET Framework.
Informazioni sulla versione
.NET Framework
Supportato in: 3.0