Reconocimiento del Texto de un Ink en WPF
En el proyecto que estamos realizando aparte de la entrada anterior necesitamos que en un Ink pasemos a texto lo que va escribiendo el usuario, esto es bastante sencillo si nos apoyamos en la clase InkAnalyzer que se encuentra en el assembly IAWinfx localizado en la ruta %ProgramFiles%\Reference Assemblies\Microsoft\Tablet PC\v1.7 y que solo se encuentra en los Tablet PC. Una vez añadido este assembly el código es muy sencillo.
El Xaml
- <Window x:Class="TestAnalyzer.Window1"
-
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
-
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-
- Title="TestAnalyzer"
- SizeToContent="WidthAndHeight">
-
- <Grid>
-
- <StackPanel Orientation="Vertical">
-
- <InkCanvas Name="inkCanvas" Width="600" Height="100" />
-
- <TextBox Name="textBlock" />
- </StackPanel>
- </Grid>
- </Window>
-
Tenemos un InkCanvas y un TextBox donde se ira poniendo el texto que dibuje el usuario. para hacer el reconocimiento tenemos
- public partial class Window1 : System.Windows.Window
- {
-
-
-
- InkAnalyzer _analyzer;
-
-
-
- public Window1()
- {
-
- InitializeComponent();
-
-
-
- inkCanvas.StrokeCollected +=
-
- new InkCanvasStrokeCollectedEventHandler(inkCanvas_StrokeCollected);
-
- inkCanvas.StrokeErasing +=
-
- new InkCanvasStrokeErasingEventHandler(inkCanvas_StrokeErasing);
-
-
-
- _analyzer = new InkAnalyzer();
-
- _analyzer.ResultsUpdated +=
-
- new ResultsUpdatedEventHandler(analyzer_ResultsUpdated);
-
- }
-
-
-
- void inkCanvas_StrokeErasing(object sender, InkCanvasStrokeErasingEventArgs e)
- {
-
- _analyzer.RemoveStroke(e.Stroke);
-
- _analyzer.BackgroundAnalyze();
-
- }
-
-
-
- void inkCanvas_StrokeCollected(object sender,
-
- InkCanvasStrokeCollectedEventArgs e)
- {
-
- _analyzer.AddStroke(e.Stroke);
- _analyzer.SetStrokeType(e.Stroke, StrokeType.Writing);
-
- _analyzer.BackgroundAnalyze();
-
- }
-
-
-
- void analyzer_ResultsUpdated(object sender, ResultsUpdatedEventArgs e)
- {
-
- textBlock.Text = _analyzer.GetRecognizedString();
-
- }
-
- }
-
Y ya tenemos nuestro propio OCR