首页 > 新闻 > 转:基于Aforge的手势字符识别

转:基于Aforge的手势字符识别

2010年7月29日 cvchina 发表评论 阅读评论

还是来自hellogv,呵呵。

Afroge我是第一次看到,孤陋寡闻了。下面是一点介绍。

AForge.NET is an open source C# framework designed for developers and researchers in the fields of Computer Vision and Artificial Intelligence – image processing, neural networks, genetic algorithms, fuzzy logic, machine learning, robotics, etc.

The framework is comprised by the set of libraries and sample applications, which demonstrate their features:

  • AForge.Imaging – library with image processing routines and filters;
  • AForge.Vision – computer vision library;
  • AForge.Video – set of libraries for video processing;
  • AForge.Neuro – neural networks computation library;
  • AForge.Genetic – evolution programming library;
  • AForge.Fuzzy – fuzzy computations library;
  • AForge.Robotics – library providing support of some robotics kits;
  • AForge.MachineLearning – machine learning library;
  • etc.
  • 我实现手势识别的原理很简单:捕捉运动物体+手写识别,把运动的物体的轨迹记录下来,然后通过手写识别引擎去搜索数据中最匹配的数据,从而知道“写”的是什么。目前常见的开源手写识别引擎有zinnia,wagomu 这些,不过小弟我比较业余,只把网上的比较常见的手写识别代码改进一下,只能识别字母和数字,真想通过摄像头隔空“手写”的朋友就要多花时间玩玩上面提到的几个开源手写类库了。

    本文介绍的手写识别:先在一个固定大小的画板上,用鼠标画下某图形,输入该图形对应的字母,程序把画板上的字母特征点都保存下来特征数据库(相当于学习记忆),然后再在画板上画出类似该字母的图形,程序就通过新画的特征点搜索特征数据库从而找出最类似的字母。


    接下来贴出核心代码,详细的代码请到这里下载:http://download.csdn.net/source/2312865

    GetBMPContext()是把画板中的图形的特征分析出来,Learn()是把特征与特定的字母/数字对应起来保存到数据库,Recognise()是把当前画板的图形特征从数据库中搜索,从而找出对应的字母/数字。

    const int SCAN_GAP = 10;
    private String GetBMPContext(Bitmap bmp)
    {
    Boolean bool1stScan = true;
    int ax = 0, ay = 0, bx = 0, by = 0;
    String result = “”;
    for (int i = 1; i < bmp.Width; i = i + SCAN_GAP)
    {
    for (int j = 1; j < bmp.Height; j = j + SCAN_GAP)
    {
    if (bmp.GetPixel(i, j).ToArgb() == Color.Black.ToArgb())
    {
    if (bool1stScan == false)
    {
    if (i <= ax) ax = i;
    if (i >= bx) bx = i;
    if (j <= ay) ay = j;
    if (j >= by) by = j;
    }
    else
    {
    bool1stScan = false;
    ax = i;
    bx = i;
    ay = j;
    by = j;
    }
    }
    }
    }
    Bitmap bmp2 = new Bitmap(20, 20);
    Graphics g2 = Graphics.FromImage((Image)bmp2);
    g2.Clear(Color.White);
    g2.DrawImage(bmp, new Rectangle(0, 0, bmp2.Width, bmp2.Height),
    new Rectangle(0, 0, bmp.Width, bmp.Height), GraphicsUnit.Pixel);
    g2.Dispose();
    //            pictureBox1.Image = bmp2;
    int a = 0, b = 0;
    for (int i = 0; i < bmp2.Width; i++)
    {
    for (int j = 0; j < bmp2.Height; j++)
    {
    if (bmp2.GetPixel(i, j).ToArgb() == Color.Black.ToArgb())
    result = result + “0″;
    else
    result = result + “1″;
    }
    }
    return result;
    }
    public void Learn(String name)
    {
    StreamWriter sw = new StreamWriter(fileName, true);
    sw.WriteLine(name + ” ” + GetBMPContext(bmpDraw));
    sw.Close();
    }
    public String Recognise()
    {
    String current = GetBMPContext(bmpDraw);
    StreamReader sr = new StreamReader(fileName);
    int max = 0;
    String result = “”;
    while (sr.EndOfStream == false)
    {
    String[] key = sr.ReadLine().Split(‘ ‘);
    String name = key[0];
    String data = key[1];
    int match = 0;
    for (int i = 0; i < current.Length; i++)
    {
    if (current[i] == data[i])
    match++;
    }
    if (match >= max)
    {
    result = name;
    max = match;
    }
    //Trace.WriteLine(result + “:” + match + “,” + max);
    }
    sr.Close();
    return result;
    }

    Related posts

    分类: 新闻 标签: , , , ,
    1. hardegg
      2010年7月30日20:33 | #1

      MSRA做的空中手书:
      http://blog.sina.com.cn/s/blog_4caedc7a0100eioa.html
      效果很不错。不过似乎只能识别有限个字符,而且不知道有没有后续的工作

      To cvchina:
      我刚看到回信,他们果然是通过XBOX手柄的按钮来控制轨迹的开始和结束

    2. hardegg
      2010年7月30日20:54 | #2

      我觉得空中手书最亟待解决的是如何切分字符,因为并不是每个应用场合都可以有一个手柄或类似的东西来控制一段轨迹开始和结束。这时也许可以通过短暂停顿作为一段轨迹的开始和结束标志,但这很可能会令会用户感到厌烦,而且操作起来也麻烦。

      所以如果能连续地写而不需要额外的设备和停顿就最好了,但这似乎演变成了手写字符检测,也就是在一个连续的轨迹中检测出隐藏的所有字符。想想现在CV界做单个物体检测尚有很多问题没有解决,这多个手写字符的检测也有点痴人说梦了。

      唉,纠结。

    3. 2010年7月30日21:03 | #3

      hardegg :

      MSRA做的空中手书:
      http://blog.sina.com.cn/s/blog_4caedc7a0100eioa.html
      效果很不错。不过似乎只能识别有限个字符,而且不知道有没有后续的工作

      To cvchina:
      我刚看到回信,他们果然是通过XBOX手柄的按钮来控制轨迹的开始和结束

      lame

    1. 本文目前尚无任何 trackbacks 和 pingbacks.