Shape recognition with the Tablet PC Platform InkAnalysis API

One of the cool capabilities of the Tablet PC InkAnalysis API is the ability to recognize shapes that a user draws on their Tablet PC. After you add strokes to an InkAnalyzer object and call Analyze() or BackgroundAnalyze(), you can then retrieve InkDrawingNodes by calling InkAnalyzer.FindNodesOfType() – you need to pass the enumerated value of ContextNodeType.InkDrawingNode to select only drawings. If you want to determine what the shape type is, call InkDrawingNode.GetShapeName().

Here are the shapes that our current InkAnalysis API can return:

        Ellipse

        Circle

        Triangle

        IsoscelesTriangle

        EquilateralTriangle

        RightTriangle

        Quadrilateral

        Rectangle

        Square

        Diamond

        Trapezoid

        Parallelogram

        Pentagon

        Hexagon

If the shape can not be recognized as one of the shapes listed above, "Other" will be returned.

If you are not familiar with InkAnalysis or the Tablet PC Platform SDK 1.7 and Input Supplement 1.75 (contains InkAnslysis), see the following post:

https://blogs.msdn.com/gavingear/archive/2006/09/06/743377.aspx

 

The code listed below demonstrates a basic shape recognition application, here’s a screenshot of that application running:

 

Example code:

// Basic Shape Recognition Application

// using the InkAnalysis API, part of the

// Tablet PC Platform SDK 1.75 Input Supplement

// Gavin Gear

// 01/2007

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using Microsoft.Ink;

namespace ShapeReco

{

    public partial class Form1 : Form

    {

        private InkOverlay overlay_;

        public Form1()

        {

            InitializeComponent();

        }

        private void Form1_Load(object sender, EventArgs e)

        {

            this.overlay_ = new InkOverlay(this);

            this.overlay_.Enabled = true;

        }

        private void buttonRecoShapes_Click(object sender, EventArgs e)

        {

            // Create a new InkAnalyzer referencing the strokes from

            // our InkOverlay's Ink object, and synchronized to the main Form

            InkAnalyzer analyzer = new InkAnalyzer(this.overlay_.Ink, this);

            analyzer.AddStrokes(this.overlay_.Ink.Strokes);

if (this.overlay_.Ink.Strokes.Count > 0)

{

analyzer.AddStrokes(this.overlay_.Ink.Strokes);

}

AnalysisStatus status = analyzer.Analyze();

            if (status.Successful == true)

            {

    ContextNodeCollection DrawingNodes = analyzer.FindNodesOfType(ContextNodeType.InkDrawing);

                string shapeString = "Shapes Found:" + Environment.NewLine;

                foreach (InkDrawingNode node in DrawingNodes)

             {

                    shapeString += node.GetShapeName() + Environment.NewLine;

                }

                MessageBox.Show(shapeString, "Recognized Shapes");

            }

            else

            {

                MessageBox.Show("Analysis failed, exiting");

                Application.Exit();

            }

        }

    }

}

 

This is a pretty basic example of shape recognition, but it gives you a glimpse of what’s possible with the InkAnalysis API regarding shapes and drawings. There’s a lot more capabilities in InkAnalysis for shapes including HotPoint data, and perhaps we’ll dig into that later!

If you have any questions, feel free to contact me.

 

See ya,

Gavin

ShapeReco.zip