c# - Kinect 中的手形指针

标签 c# kinect kinect-sdk

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

最佳答案

在 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# SampleInteractionGallery-WPF C# Sample .

关于c# - Kinect 中的手形指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17176215/

相关文章:

c# - DataStax Cassandra C# 驱动程序 : WHERE IN (? ) 使用集合参数进行查询

c# - 在Windows Docker上安装Matlab

c++ - PCL OpenNI2Grabber 在没有查看器的情况下获取点云

c# - Kinect,警告 : An ImageFrame instance was not Disposed

c++ - Qt Creator - 设置架构标志

c# - 使用 Kinect 录制音频

c# - 将 IOrderedEnumerable<KeyValuePair<string, int>> 转换为 Dictionary<string, int>

c# 缺少命名空间 Windows

face-detection - 是否可以将Microsoft面部跟踪SDK与本地镜像一起使用

c# - Kinect SDK 损坏内存错误