WPF下System.Windows.Ink的手写识别率

.Net技术 码拜 9年前 (2015-03-20) 2679次浏览 0个评论
WPF下,用了InkCanvas控件和System.Windows.Ink进行手写识别。识别率还算可以。
但是用了下 任务栏-》工具栏-》tablet pc输入面板 中的手写识别后就不淡定了。
识别率咋就相差这么大呢?系统自带的这个工具咋就这么好使呢?难道调用不是同一个识别库文件吗?都有tablet pc字样啊?
//添加对 WPF 墨迹分析程序集、IAWinFX.dll、IACore.dll 和 IALoader.dll(这些内容可以在 \Program Files\Reference Assemblies\Microsoft\Tablet PC\v1.7 中找到)的引用。
using System.Windows.Ink;
    // Recognizes handwriting by using RecognizerContext
    private void buttonClick(object sender, RoutedEventArgs e)
    {
      InkAnalyzer theInkAnalyzer = new InkAnalyzer();
      theInkAnalyzer.AddStrokes(theInkCanvas.Strokes);
      theInkAnalyzer.SetStrokesLanguageId(theInkCanvas.Strokes, 0x0804);  // 0x0804 简体中文
      theInkAnalyzer.SetStrokesType(theInkCanvas.Strokes, StrokeType.Writing);
      AnalysisStatus status = theInkAnalyzer.Analyze();
      if (status.Successful)
      {
        //textBox1.Text = theInkAnalyzer.GetRecognizedString();
        textBox1.Text = “”;
        for (int i = 0; i < theInkAnalyzer.GetAlternates().Count; i++)
        {
          textBox1.Text += theInkAnalyzer.GetAlternates()[i].RecognizedString;
        }
      }
      else
      {
        MessageBox.Show(“识别失败”);
      }
    }

tablet pc输入面板是调用的哪个识别库?可否在WPF程序中调用它?达到tablet pc输入面板那样高的识别率?
如果换种方式在程序中打开tablet pc输入面板窗口的话,
又比较担心用户会通过点击输入窗口的选项或者帮助切换出主程序界面。

 
WPF下System.Windows.Ink的手写识别率
在msdn上面下载的,地址忘了。好像是一个就做TabletPC.exe的自解压包。
文件名称是inkrecognition(试试能搜到不)。
以下为原始内容:
pre class=”brush: C#”>
// THIS CODE AND INFORMATION IS PROVIDED “AS IS” WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//  File: InkRecognition.cs
//  Simple Ink Recognition Sample Application
//
//  This program demonstrates how one can build a basic handwriting 
//  recognition application using Microsoft Tablet PC Automation API. 
//  It first creates an InkCollector object to enable inking
//  in the window. Upon receiving the “Recognize!” command, fired
//  from the application”s button, ToString() is invoked on the 
//  collected ink strokes to retrieve the best match using the
//  default recognizer.  The results are presented in a message box.
//
//  The features used are: InkCollector, Ink, Strokes, 
//  RecognizerContext, and RecognizerResult
//
//————————————————————————–
using System;
using System.Drawing;
using System.Windows.Forms;
// The Ink namespace, which contains the Tablet PC Platform API
using Microsoft.Ink;
namespace Microsoft.Samples.TabletPC.InkRecognition
{
    /// <summary>
    /// The InkRecognition Sample Application form class
    /// </summary>
    public class InkRecognition : System.Windows.Forms.Form
    {
        // Declare the Ink Collector object
        private InkCollector myInkCollector = null;
        // myRecognizers is used to retrieve the number of installed recognizers
        Recognizers myRecognizers;
        #region Standard Template Code
        private System.Windows.Forms.GroupBox gbInkArea;
        private System.Windows.Forms.Button btnRecognize;
        private System.Windows.Forms.TextBox txtResults;
        private System.ComponentModel.Container components = null;
        #endregion
        /// <summary>
        /// Initialize the form and ink collector
        /// </summary>
        public InkRecognition()
        {
            #region Standard Template Code
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            #endregion
           
        }
        #region Standard Template Code
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (components != null) 
                {
                    components.Dispose();
                }
                if (myInkCollector != null)
                {
                    myInkCollector.Dispose();
                }
            }
            base.Dispose( disposing );
        }
        #endregion
        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support – do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.gbInkArea = new System.Windows.Forms.GroupBox();
            this.btnRecognize = new System.Windows.Forms.Button();
            this.txtResults = new System.Windows.Forms.TextBox();
            this.SuspendLayout();
            // 
            // gbInkArea
            // 
            this.gbInkArea.Location = new System.Drawing.Point(8, 0);
            this.gbInkArea.Name = “gbInkArea”;
            this.gbInkArea.Size = new System.Drawing.Size(280, 136);
            this.gbInkArea.TabIndex = 0;
            this.gbInkArea.TabStop = false;
            this.gbInkArea.Text = “Ink Here”;
            // 
            // btnRecognize
            // 
            this.btnRecognize.Location = new System.Drawing.Point(8, 144);
            this.btnRecognize.Name = “btnRecognize”;
            this.btnRecognize.Size = new System.Drawing.Size(280, 23);
            this.btnRecognize.TabIndex = 1;
            this.btnRecognize.Text = “Recognize Ink”;
            this.btnRecognize.Click += new System.EventHandler(this.btnRecognize_Click);
            // 
            // txtResults
            // 
            this.txtResults.BackColor = System.Drawing.SystemColors.Window;
            this.txtResults.ForeColor = System.Drawing.SystemColors.WindowText;
            this.txtResults.Location = new System.Drawing.Point(8, 176);
            this.txtResults.Name = “txtResults”;
            this.txtResults.ReadOnly = true;
            this.txtResults.Size = new System.Drawing.Size(280, 20);
            this.txtResults.TabIndex = 2;
            this.txtResults.Text = “”;
            // 
            // InkRecognition
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(292, 206);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.txtResults,
                                                                          this.btnRecognize,
                                                                          this.gbInkArea});
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.MaximizeBox = false;
            this.Name = “InkRecognition”;
            this.Text = “Ink Recognition Sample”;
            this.Load += new System.EventHandler(this.InkRecognition_Load);
            this.ResumeLayout(false);
        }
        #endregion
        #region Standard Template Code
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new InkRecognition());
        }
        #endregion
        /// <summary>
        /// Event Handler from Form Load Event
        /// Setup the ink collector for collection
        /// </summary>
        /// <param name=”sender”>The control that raised the event.</param>
        /// <param name=”e”>The event arguments.</param>
        private void InkRecognition_Load(object sender, System.EventArgs e)
        {
            // Create the recognizers collection
            myRecognizers = new Recognizers();
            // Create a new ink collector that uses the group box handle
            myInkCollector = new InkCollector(gbInkArea.Handle);
            // Turn the ink collector on
            myInkCollector.Enabled = true;          
     
        }
        /// <summary>
        /// Event Handle recognize button click event
        /// </summary>
        /// <param name=”sender”>The control that raised the event.</param>
        /// <param name=”e”>The event arguments.</param>
        private void btnRecognize_Click(object sender, System.EventArgs e)
        {
            // Check to ensure that the user has at least one recognizer installed
            // Note that this is a preventive check – otherwise, an exception will
            // occur during recognition.
            if (0 == myRecognizers.Count)
            {
                MessageBox.Show(“There are no handwriting recognizers installed.  You need to have at least one in order to recognize ink.”);
            }
            else
            {
                // Note that the Strokes” ToString() method is a 
                // shortcut  for retrieving the best match using the  
                // default recognizer.  The same result can also be 
                // obtained using the RecognizerContext.  For an 
                // example, uncomment the following lines of code:
                // 
                // using (RecognizerContext myRecoContext = new RecognizerContext())
                // {
                //     RecognitionStatus status;
                //     RecognitionResult recoResult;
                //
                //     myRecoContext.Strokes = myInkCollector.Ink.Strokes;
                //     recoResult = myRecoContext.Recognize(out status);
                //     txtResults.SelectedText = recoResult.TopString;
                // }
                txtResults.SelectedText = myInkCollector.Ink.Strokes.ToString();
                // If the mouse is pressed, do not perform the deletion – 
                // this prevents deleting a stroke that is still being drawn
                if (!myInkCollector.CollectingInk)
                {
                    // Once the strokes have been recognized, delete them
                    myInkCollector.Ink.DeleteStrokes();
                    // Repaint the drawing area
                    gbInkArea.Refresh();
                }
            }
        }
    }
}
/pre>
WPF下System.Windows.Ink的手写识别率
请问一下楼主,为什么我用了你的代码,执行到theInkAnalyzer.AddStrokes(theInkCanvas.Strokes);这一句的时候就会导致整个程序异常关闭呢?求指导……
WPF下System.Windows.Ink的手写识别率
wpf下的添加那几个dll文件的引用了么?
//IAWinFX.dll、IACore.dll 和 IALoader.dll(这些内容可以在 \Program Files\Reference Assemblies\Microsoft\Tablet PC\v1.7 中找到)的引用。
5楼的方法是winform下的。
已上传http://download.csdn.net/detail/slowhand/4402438
这里有个wpf下很好用的,dll文件在项目里,识别率蛮高的。
a href=”https://skydrive.live.com/?cid=51b2fdd068799d15&sc=documents&id=51B2FDD068799D15%21686″ target=”_blank”>https://skydrive.live.com/?cid=51b2fdd068799d15&sc=documents&id=51B2FDD068799D15%21686
(下载地址在右上角)
WPF下System.Windows.Ink的手写识别率
楼主,我跑了你的程序
AnalysisStatus status = theInkAnalyzer.Analyze();
status.Successful总是false,什么原因,还在查
WPF下System.Windows.Ink的手写识别率
看了下MSDN上的那个demo和楼主的一样
MSDN上有这几句“此示例要求在系统上安装手写识别器。”
“添加对 WPF 墨迹分析程序集、IAWinFX.dll、IACore.dll 和 IALoader.dll(这些内容可以在 \Program Files\Reference Assemblies\Microsoft\Tablet PC\v1.7 中找到)的引用。”
我的系统上有没有手写识别器我不清楚(是不是xp自带识别器?反正我没装过)
但是“\Program Files\Reference Assemblies\Microsoft\Tablet PC\v1.7”这里面没有IALoader.dll,IAWinFX.dll和IACore.dll都有
是不是这个问题导致我总是识别失败
WPF下System.Windows.Ink的手写识别率
引用 9 楼 liu610721 的回复:

看了下MSDN上的那个demo和楼主的一样
MSDN上有这几句“此示例要求在系统上安装手写识别器。”
“添加对 WPF 墨迹分析程序集、IAWinFX.dll、IACore.dll 和 IALoader.dll(这些内容可以在 \Program Files\Reference Assemblies\Microsoft\Tablet PC\v1.7 中找到)的引用。”
我的系统上有没有手写识别器我不清楚(是不是xp自带识别器?反正我没装过)
但是“\Program Files\Reference Assemblies\Microsoft\Tablet PC\v1.7”这里面没有IALoader.dll,IAWinFX.dll和IACore.dll都有
是不是这个问题导致我总是识别失败

1、Windows7系统: 正常
2、Windows Embedded Standard系统:   
   我设置为英文可以,但是设置为中文就识别不了,
   我遇到的问题和你一样 我的系统是Windows Embedded Standard   楼主求答案! 
/div>

WPF下System.Windows.Ink的手写识别率
引用 10 楼 shaoshao19890119 的回复:
Quote: 引用 9 楼 liu610721 的回复:

看了下MSDN上的那个demo和楼主的一样
MSDN上有这几句“此示例要求在系统上安装手写识别器。”
“添加对 WPF 墨迹分析程序集、IAWinFX.dll、IACore.dll 和 IALoader.dll(这些内容可以在 \Program Files\Reference Assemblies\Microsoft\Tablet PC\v1.7 中找到)的引用。”
我的系统上有没有手写识别器我不清楚(是不是xp自带识别器?反正我没装过)
但是“\Program Files\Reference Assemblies\Microsoft\Tablet PC\v1.7”这里面没有IALoader.dll,IAWinFX.dll和IACore.dll都有
是不是这个问题导致我总是识别失败

1、Windows7系统: 正常
2、Windows Embedded Standard系统:   
   我设置为英文可以,但是设置为中文就识别不了,
   我遇到的问题和你一样 我的系统是Windows Embedded Standard   楼主求答案! 
/blockquote>

win7自带tabletPC,windowsXp需要下一个tabletPC,里面有demo,可以看下   识别率还是挺高的

WPF下System.Windows.Ink的手写识别率
引用 11 楼 liu610721 的回复:
Quote: 引用 10 楼 shaoshao19890119 的回复:

fieldset>

Quote: 引用 9 楼 liu610721 的回复:

看了下MSDN上的那个demo和楼主的一样
MSDN上有这几句“此示例要求在系统上安装手写识别器。”
“添加对 WPF 墨迹分析程序集、IAWinFX.dll、IACore.dll 和 IALoader.dll(这些内容可以在 \Program Files\Reference Assemblies\Microsoft\Tablet PC\v1.7 中找到)的引用。”
我的系统上有没有手写识别器我不清楚(是不是xp自带识别器?反正我没装过)
但是“\Program Files\Reference Assemblies\Microsoft\Tablet PC\v1.7”这里面没有IALoader.dll,IAWinFX.dll和IACore.dll都有
是不是这个问题导致我总是识别失败

1、Windows7系统: 正常
2、Windows Embedded Standard系统:   
   我设置为英文可以,但是设置为中文就识别不了,
   我遇到的问题和你一样 我的系统是Windows Embedded Standard   楼主求答案! 
/blockquote>

win7自带tabletPC,windowsXp需要下一个tabletPC,里面有demo,可以看下   识别率还是挺高的
谢谢啊  
我是Windows Embedded Standard系统缺少语言组件

WPF下System.Windows.Ink的手写识别率
引用 9 楼 liu610721 的回复:

看了下MSDN上的那个demo和楼主的一样
MSDN上有这几句“此示例要求在系统上安装手写识别器。”
“添加对 WPF 墨迹分析程序集、IAWinFX.dll、IACore.dll 和 IALoader.dll(这些内容可以在 \Program Files\Reference Assemblies\Microsoft\Tablet PC\v1.7 中找到)的引用。”
我的系统上有没有手写识别器我不清楚(是不是xp自带识别器?反正我没装过)
但是“\Program Files\Reference Assemblies\Microsoft\Tablet PC\v1.7”这里面没有IALoader.dll,IAWinFX.dll和IACore.dll都有
是不是这个问题导致我总是识别失败

   
我现在就是这个情况,请你问你怎么搞定的?


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明WPF下System.Windows.Ink的手写识别率
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!