有人知道如何使用Kinect SDK 1.7的HandPointer
类吗?
我一直在尝试创建一个HandPointer
类的对象hand
,并在手被Gripped时向控制台打印一条消息,但没有成功。我无法创建hand
对象。
以下是 HandPointer
class 的 MSDN 链接和 HandPointer
members .
这是一个示例代码段:
//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
类没有任何公共(public)构造函数,因此您无法执行此操作。它本质上是一个抽象类。在这种情况下,您似乎需要创建 KinectRegion
class 的实例并访问其 HandPointers
property .
完全不熟悉 Kinect 编程,我无法提供任何关于设置 KinectRegion
的建议;您必须咨询C# samples包含在 SDK 中。看起来最适合您的两个是 Controls Basics WPF-C# Sample和 InteractionGallery-WPF C# Sample .
关于c# - Kinect 中的手形指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17176215/