Here is to introduce the use of Inkanalyzer to achieve simple graphics recognition, such as circles, ellipses, squares, triangles, etc., of course, you can also expand to achieve the recognition of custom graphics, before using Inkanalyzer, You need to quote IAWinFX.dll in order to guarantee inkanalyzer normal work.
PS: Through the Inkanalyzer to achieve simple graphics recognition, is not a very advanced technology, in addition to Inkanalyzer you can also use some existing algorithms to realize the handwriting to the graphics recognition conversion, but we work in the window platform, using the net technology, So there is no need to reinvent the wheel, this article is actually a small function of the Drawtool tool is the graphic recognition pen. For Drawtool In addition to the need to have a brush, highlighter, Flash pen, tole, texture pen, but also need a graphic recognition pen support.
The code is relatively simple and the use of related classes can be referred to MSDN, which is your best companion.
For the recognition of custom graphics, you can in the _internalanalyzer function, when Drawingnode.getshapename returns the name of other time, and then according to the handwriting analysis, is actually the application of the point analysis algorithm
/// <summary> ///graphic Recognition class/// </summary> Public classShaperecogniser { PublicInkAnalyzer _inkanalyzer =NULL; PrivateShaperecogniser () { This. _inkanalyzer =NewInkAnalyzer {analysismodes=analysismodes.automaticreconciliationenabled}; } /// <summary> ///returns a graphic name string based on a collection of strokes/// </summary> /// <param name= "StrokeCollection" ></param> /// <returns></returns> Public stringrecognition (StrokeCollection strokecollection) {if(StrokeCollection = =NULL) {MessageBox.Show ("dddddd"); return NULL; } stringresult =NULL; Try { This. _inkanalyzer.addstrokes (StrokeCollection); if( This. _inkanalyzer.analyze (). Successful) {result= _internalanalyzer ( This. _inkanalyzer); This. _inkanalyzer.removestrokes (StrokeCollection); } } Catch(System.Exception ex) {System.Diagnostics.Debug.WriteLine (ex). Message); } returnresult; } /// <summary> ///Implements handwriting analysis, returns the string corresponding to the graphic///you generate the corresponding shape in the actual application based on the returned string/// </summary> /// <param name= "Ink" ></param> /// <returns></returns> Private string_internalanalyzer (InkAnalyzer ink) {Try{contextnodecollection nodecollections=Ink. Findnodesoftype (contextnodetype.inkdrawing); foreach(ContextNode nodeinchnodecollections) {Inkdrawingnode Drawingnode= Node asInkdrawingnode; if(Drawingnode! =NULL) { returnDrawingnode.getshapename (); } } } Catch(System.Exception ex) {System.Diagnostics.Debug.WriteLine (ex). Message); } return NULL; } Private StaticShaperecogniser instance =NULL; Public Staticshaperecogniser Instance {Get { returnInstance = =NULL? (Instance =NewShaperecogniser ()): instance; } } }
The application is actually very simple, you can add a inkcanvas on any of your programs, and then in the mouse up or where you feel fit by calling Shaperecogniser's recognition method, and then generating the corresponding shape based on the name of the returned graphic
--------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------
The prelude of Drawtool Multi-pen and realize the pattern recognition through Inkanalyzer