如何使用Microsoft Kinect for Windows SDK版本1.7 C#检测打开/关闭的手 [英] How to detect open/closed hand using Microsoft Kinect for Windows SDK ver 1.7 C#
问题描述
我最近开始使用Microsoft Kinect for Windows SDK来使用Kinect设备对某些内容进行编程.
I have recently started using Microsoft Kinect for Windows SDK to program some stuff using the Kinect the device.
我正在捣蛋,寻找一种方法来检测某只手是闭合还是张开.
I am busting my ass to find a way to detect whether a certain hand is closed or opened.
我看到了Kinect for Windows Toolkit,但是该文档不存在,我找不到使它工作的方法.
I saw the Kinect for Windows Toolkit but the documentation is none existent and I can't find a way to make it work.
有人知道一种检测手部状况的简单方法吗?如果它不需要使用Kinect工具包,那就更好了.
Does anyone knows of a simple way to detect the hand's situation? even better if it doesn't involve the need to use the Kinect toolkit.
推荐答案
这是我最终做到的方式:
This is how I did it eventually:
首先,我们需要一个看起来像这样的伪类:
First things first, we need a dummy class that looks somewhat like this:
public class DummyInteractionClient : IInteractionClient
{
public InteractionInfo GetInteractionInfoAtLocation(
int skeletonTrackingId,
InteractionHandType handType,
double x,
double y)
{
var result = new InteractionInfo();
result.IsGripTarget = true;
result.IsPressTarget = true;
result.PressAttractionPointX = 0.5;
result.PressAttractionPointY = 0.5;
result.PressTargetControlId = 1;
return result;
}
}
然后,在主要应用程序代码中,我们需要宣布有关交互事件处理程序的信息,如下所示:
Then, in the main application code we need to announce about the interactions events handler like this:
this.interactionStream = new InteractionStream(args.NewSensor, new DummyInteractionClient());
this.interactionStream.InteractionFrameReady += InteractionStreamOnInteractionFrameReady;
最后,是处理程序本身的代码:
Finally, the code to the handler itself:
private void InteractionStreamOnInteractionFrameReady(object sender, InteractionFrameReadyEventArgs e)
{
using (InteractionFrame frame = e.OpenInteractionFrame())
{
if (frame != null)
{
if (this.userInfos == null)
{
this.userInfos = new UserInfo[InteractionFrame.UserInfoArrayLength];
}
frame.CopyInteractionDataTo(this.userInfos);
}
else
{
return;
}
}
foreach (UserInfo userInfo in this.userInfos)
{
foreach (InteractionHandPointer handPointer in userInfo.HandPointers)
{
string action = null;
switch (handPointer.HandEventType)
{
case InteractionHandEventType.Grip:
action = "gripped";
break;
case InteractionHandEventType.GripRelease:
action = "released";
break;
}
if (action != null)
{
string handSide = "unknown";
switch (handPointer.HandType)
{
case InteractionHandType.Left:
handSide = "left";
break;
case InteractionHandType.Right:
handSide = "right";
break;
}
if (handSide == "left")
{
if (action == "released")
{
// left hand released code here
}
else
{
// left hand gripped code here
}
}
else
{
if (action == "released")
{
// right hand released code here
}
else
{
// right hand gripped code here
}
}
}
}
}
}
这篇关于如何使用Microsoft Kinect for Windows SDK版本1.7 C#检测打开/关闭的手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!