【问题标题】:Gesture recognition using OpenNI, NiTE, C#, Xtion Pro Live device使用 OpenNI、NiTE、C#、Xtion Pro Live 设备进行手势识别
【发布时间】:2014-08-13 20:34:14
【问题描述】:

在我的应用程序中,使用来自 ASUS Xtion Pro Live 设备的输入,我想利用 NiTE 进行手势识别,因为我自己的基于 OpenNI 框架功能的手势识别代码笨重且不完全可靠。

我使用的是 OpenNI.net.dll v1.5.2.23 和 XnVNITE.net.dll v1.5.2.21,这是设备 CD 上的内容。似乎他们无论如何都没有为 v2 制作 .NET 包装器。

只是为了起步,我根据 NiHandViewer/HandViewer.java 示例编写了一些代码,但它没有做任何事情,没有触发任何事件,而且我找不到任何有用的 NiTE C# 示例为我指明正确的方向。

下面的代码有什么问题?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenNI;
using NITE;
using System.Threading.Tasks;

namespace NiTEPlayground
{
    static class Point3DExtensions
    {
        public static string ToTripletString(this Point3D point3d)
        {
            return String.Format("({0}, {1}, {2})", point3d.X, point3d.Y, point3d.Z);
        }
    }

    class Program
    {
        static Context context;
        static GestureGenerator generator;
        static HandsGenerator handsGen;

        static void Main(string[] args)
        {
            ScriptNode scriptNode;
            context = Context.CreateFromXmlFile("SamplesConfig.xml", out scriptNode);

            generator = new GestureGenerator(context);
            generator.AddGesture("Wave");
            generator.AddGesture("Click");
            generator.GestureRecognized += new EventHandler<GestureRecognizedEventArgs>(generator_GestureRecognized);
            generator.GestureProgress += new EventHandler<GestureProgressEventArgs>(generator_GestureProgress);

            handsGen = new HandsGenerator(context);
            handsGen.HandCreate += new EventHandler<HandCreateEventArgs>(handsGen_HandCreate);
            handsGen.HandUpdate += new EventHandler<HandUpdateEventArgs>(handsGen_HandUpdate);
            handsGen.HandDestroy += new EventHandler<HandDestroyEventArgs>(handsGen_HandDestroy);

            context.StartGeneratingAll();

            Task.Factory.StartNew(() =>
            {
                while (true)
                {
                    context.WaitAnyUpdateAll();
                }
            });

            Console.ReadKey();
        }

        static void generator_GestureProgress(object sender, GestureProgressEventArgs e)
        {
            Console.WriteLine("Gesture Progress: {0}; {1}; {2}", e.Gesture, e.Position.ToTripletString(), e.Progress);
        }

        static void handsGen_HandDestroy(object sender, HandDestroyEventArgs e)
        {
            Console.WriteLine("Hand Create: {0}, {1}", e.UserID, e.Time);
        }

        static void handsGen_HandUpdate(object sender, HandUpdateEventArgs e)
        {
            Console.WriteLine("Hand Update: {0}, {1}, {2}", e.UserID, e.Time, e.Position.ToTripletString());
        }

        static void handsGen_HandCreate(object sender, HandCreateEventArgs e)
        {
            Console.WriteLine("Hand Create: {0}, {1}, {2}", e.UserID, e.Time, e.Position.ToTripletString());
        }

        static void generator_GestureRecognized(object sender, GestureRecognizedEventArgs e)
        {
            Console.WriteLine("Gesture:{0}; Identified:{1}; End:{2}", e.Gesture, e.IdentifiedPosition.ToTripletString(), e.EndPosition.ToTripletString());
        }
    }
}

【问题讨论】:

    标签: c# openni asus-xtion nite


    【解决方案1】:

    我试过你的代码,它对我有用。

    要启用手部追踪,您需要开始追踪:

    只需替换:

    static void generator_GestureRecognized(object sender, GestureRecognizedEventArgs e)
            {
                Console.WriteLine("Gesture:{0}; Identified:{1}; End:{2}", e.Gesture, e.IdentifiedPosition.ToTripletString(), e.EndPosition.ToTripletString());
            }
    
    
    static void generator_GestureRecognized(object sender, GestureRecognizedEventArgs e)
            {
                handsGen.StartTracking(e.EndPosition);
                Console.WriteLine("Gesture:{0}; Identified:{1}; End:{2}", e.Gesture,     e.IdentifiedPosition.ToTripletString(), e.EndPosition.ToTripletString());
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-21
      • 2013-11-25
      • 2016-01-01
      • 1970-01-01
      • 2014-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多