Kinect中的手部指针

本文关键字:指针 手部 Kinect | 更新日期: 2023-09-27 18:18:51

有谁知道如何使用Kinect SDK 1.7的HandPointer类吗?

我一直试图使HandPointer类的对象hand,并在手握住时向控制台打印一条消息,但没有成功。我无法创建hand对象。

以下是HandPointer类和HandPointer成员的MSDN链接。

下面是一个示例代码段:

//First I make the HandPointer object:
HandPointer hand;
//then later I check :
if (hand.IsInGripInteraction)
  Console.WriteLine("The hand is gripped");

错误是当我运行代码时,我的HandPointer对象handnull。是否有任何初始化需要运行?

Kinect中的手部指针

在c#中,所有类都是引用类型。引用类型变量默认为null,因此您通常需要使用new关键字创建该类的实例并将其赋值:

List<string> names; // starts off as null
// the following line would cause a null reference exception
// names.Add("names");
names = new List<string>(); // create an instance
// now you can safely work with it
names.Add("names");
// of course, you can also initialize when you declare
List<string> names2 = new List<string>();
names2.Add("names2");
但是,根据您链接的文档,HandPointer类没有任何公共构造函数,因此您不能这样做。它本质上是一个抽象类。在这种情况下,似乎您需要创建KinectRegion类的实例并访问其HandPointers属性。

由于不熟悉Kinect编程,我无法提供任何关于设置KinectRegion的建议;你必须查阅SDK附带的c#示例。两个看起来最适合你的是Controls Basics wpf - c# Sample和interaction过敏原- wpf c# Sample。