RecognizerContext.BackgroundRecognizeWithAlternates (Método)
Actualización: noviembre 2007
Hace que el objeto Recognizer reconozca la colección Strokes la asociada y se provoca un evento RecognitionWithAlternates, con datos de la aplicación asociados, cuando el reconocimiento ha finalizado.
Espacio de nombres: Microsoft.Ink
Ensamblado: Microsoft.Ink (en Microsoft.Ink.dll)
Sintaxis
'Declaración
Public Sub BackgroundRecognizeWithAlternates
'Uso
Dim instance As RecognizerContext
instance.BackgroundRecognizeWithAlternates()
public void BackgroundRecognizeWithAlternates()
public:
void BackgroundRecognizeWithAlternates()
public void BackgroundRecognizeWithAlternates()
public function BackgroundRecognizeWithAlternates()
Comentarios
Este método especifica que el reconocimiento de entradas manuscritas se realiza de forma asincrónica.
Para realizar un reconocimiento que incluya solamente las alternativas principales, llame al método BackgroundRecognize.
No se provoca el evento RecognitionWithAlternates si el reconocedor no reconoce ninguna alternativa.
Ejemplos
En este ejemplo, cada trazo creado en un objeto InkOverlay se reconoce automáticamente y se muestran los resultados del reconocimiento, incluidas las alternativas.
Durante el inicio de la aplicación, se crea una instancia del objeto RecognizerContext y se asignan controladores de eventos.
' 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_Stroke1)
' subscribe to the the RecognitionWithAlternates event.
' This event is fired when background recognition is complete,
' and recognition results (with alternates) are available
AddHandler mRecognizerContext.RecognitionWithAlternates, _
New RecognizerContextRecognitionWithAlternatesEventHandler(AddressOf mRecognizerContext_RecognitionWithAlternates)
// 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_Stroke1);
// subscribe to the the RecognitionWithAlternates event.
// This event is fired when background recognition is complete,
// and recognition results (with alternates) are available
mRecognizerContext.RecognitionWithAlternates +=
new RecognizerContextRecognitionWithAlternatesEventHandler(mRecognizerContext_RecognitionWithAlternates);
Cuando se activa el evento Stroke (en respuesta a la finalización de un trazo por parte del usuario), el trazo recién creado se agrega a la colección Strokes del objeto RecognizerContext y se llama al método BackgroundRecognizeWithAlternates.
Private Sub mInkOverlay_Stroke1(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.BackgroundRecognizeWithAlternates()
End Sub
private void mInkOverlay_Stroke1(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.BackgroundRecognizeWithAlternates();
}
Cuando se completa el reconocimiento en segundo plano, se desencadena el evento RecognitionWithAlternates. Durante el control de este evento, los resultados del reconocimiento (incluidas las alternativas) se introducen en un cuadro de lista.
' event fires when recognition results (with alternates) are ready
Private Sub mRecognizerContext_RecognitionWithAlternates(ByVal sender As Object, _
ByVal e As RecognizerContextRecognitionWithAlternatesEventArgs)
' 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 RecognizerContextRecognitionWithAlternatesEventHandler(AddressOf mRecognizerContext_RecognitionWithAlternates), _
New Object() {sender, e} _
)
Return
End If
If RecognitionStatus.NoError = e.RecognitionStatus Then
' show the top alternate
listBoxRecognitionResults.Items.Add("TOP:" + e.Result.TopAlternate.ToString())
' get the rest of the alternates
Dim allAlternates As RecognitionAlternates = e.Result.GetAlternatesFromSelection()
' show each of the other alternates
For Each oneAlternate As RecognitionAlternate In allAlternates
listBoxRecognitionResults.Items.Add("ALT:" + oneAlternate.ToString())
Next
End If
End Sub
// event fires when recognition results (with alternates) are ready
private void mRecognizerContext_RecognitionWithAlternates(object sender, RecognizerContextRecognitionWithAlternatesEventArgs 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 RecognizerContextRecognitionWithAlternatesEventHandler(mRecognizerContext_RecognitionWithAlternates),
new object[] { sender, e }
);
return;
}
if (RecognitionStatus.NoError == e.RecognitionStatus)
{
// show the top alternate
listBoxRecognitionResults.Items.Add("TOP:" + e.Result.TopAlternate.ToString());
// get the rest of the alternates
RecognitionAlternates allAlternates = e.Result.GetAlternatesFromSelection();
// show each of the other alternates
foreach (RecognitionAlternate oneAlternate in allAlternates)
{
listBoxRecognitionResults.Items.Add("ALT:" + oneAlternate.ToString());
}
}
}
Plataformas
Windows Vista
.NET Framework y .NET Compact Framework no admiten todas las versiones de cada plataforma. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.
Información de versión
.NET Framework
Compatible con: 3.0
Vea también
Referencia
BackgroundRecognizeWithAlternates (Sobrecarga)
Microsoft.Ink (Espacio de nombres)
BackgroundRecognizeWithAlternates