有谁知道如何使用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
对象hand
是null
。是否有任何初始化需要运行?
在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。