如何使用Microsoft Kinect for Windows SDK 1.7 C版检测打开/闭合的手#

如何使用Microsoft Kinect for Windows SDK 1.7 C版检测打开/闭合的手#,sdk,kinect,Sdk,Kinect,我最近开始使用Microsoft Kinect for Windows SDK,使用Kinect设备编程一些东西 我拼命想找到一种方法来检测某只手是关着的还是开着的 我看到了Kinect for Windows工具包,但该文档不存在,我无法找到使其工作的方法 有人知道一种检测手部状况的简单方法吗?如果不需要使用Kinect toolkit,那就更好了。据我所知,Microsoft Kinect For windows SDK最不适合检测手的张开和闭合。Microsoft提供20个部件的跟踪,不包

我最近开始使用Microsoft Kinect for Windows SDK,使用Kinect设备编程一些东西

我拼命想找到一种方法来检测某只手是关着的还是开着的

我看到了Kinect for Windows工具包,但该文档不存在,我无法找到使其工作的方法


有人知道一种检测手部状况的简单方法吗?如果不需要使用Kinect toolkit,那就更好了。

据我所知,Microsoft Kinect For windows SDK最不适合检测手的张开和闭合。Microsoft提供20个部件的跟踪,不包括手的手指。您可以以一种直观的方式利用kinect交互。本教程介绍了如何:

但我认为跟踪手指运动的最佳解决方案是使用SDK


OpenNI的一些功能允许手指跟踪。

SDK1.7引入了称为“抓地力”的交互概念。您可以通过以下链接了解所有
KinectInteraction
概念:

微软实现这一点的方式是通过一个来自。其中有和,它们在适当的时候开火。由于事件来自元素,因此您可以轻松地从事件处理程序中采取适当的操作

请注意,
KinectRegion
可以是任何内容。基类是一个
ContentControl
,因此您可以将像图像这样简单的内容放置到要操作的区域内的复杂
网格
布局中

您可以在SDK提供的中找到如何使用此交互的示例

更新:

KinectRegion
只是一个花哨的
ContentControl
,而它又只是一个容器,里面可以放任何东西。查看位于的示例,并在文件中搜索
KinectRegion
。您将看到,它内部有多个控件,这些控件将被操作


要查看本例中如何实现
Grip
GripRelease
,最好在Visual Studio中打开解决方案并搜索“Grip”。在我看来,他们这样做有点奇怪,但这是一个干净的实现,流程非常好

private void OnHandleHandMove(object source, HandPointerEventArgs args)
    {
        HandPointer ptr = args.HandPointer;
        if (ptr.HandEventType==HandEventType.Grip)
        {
           // TODO
        }
    }

我最终就是这样做的:

首先,我们需要一个类似以下内容的虚拟类:

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;
    }
}
this.interactionStream = new InteractionStream(args.NewSensor, new DummyInteractionClient());
                this.interactionStream.InteractionFrameReady += InteractionStreamOnInteractionFrameReady;
然后,在主应用程序代码中,我们需要宣布交互事件处理程序,如下所示:

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;
    }
}
this.interactionStream = new InteractionStream(args.NewSensor, new DummyInteractionClient());
                this.interactionStream.InteractionFrameReady += InteractionStreamOnInteractionFrameReady;
最后,将代码添加到处理程序本身:

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
                        }
                    }
                }
            }
        }
    }

不幸的是,链接中提供的代码不适用于我。我不知道为什么,相机甚至不能启动。不再是真的了。有了kinect sdk 1.7,MS本机支持它。我已经测试了Quicksoul提供的代码。对我来说它确实有效。代码对jacob不起作用可能是因为kinect版本。也许雅各布会使用xbox 360版本。博客中的代码试图激活xbox 360版本中没有的near模式。我还使用了Xbox360版本。它在一开始对我不起作用,但后来我对代码做了一些修改并开始工作。@CodingWolf你能分享一个检测拳头和握把释放手势的工作代码示例吗?如果你能分享它的链接,我将不胜感激。这是我的电子邮件:法赞。zad@gmail.comTried它的文档非常有限,很难弄清楚它是如何工作的。为了确保我对你的理解正确,我可以将任何东西设置为“KinectRegion”?好吧,我设法让这个区域工作起来。但是,我找不到一种方法来创建握拍和放松的事件。有什么见解吗?我遇到了同样的问题:我可以创建一个类型为“KinectRegion”的XAML元素,但我无法使用类似以下内容设置其“Grip”-事件处理程序:
,谢谢您的回答!我尝试将您的代码添加到我的项目中,但它表明我的项目不包含interactionStream的定义。我是初学者!您能把整个代码放在一个示例.sln文件中并共享吗?我正在运行kinect SDK 1.8,它还提供了在dummyclass中创建的“InteractionHandType”错误。。尽管我已经包括了“使用Microsoft.Kinect.Toolkit.Interaction”,但请有人帮忙~!有关将Microsoft.Kinect.Toolkit.Interaction添加到项目的详细信息,请参阅。在dummyclass中创建的“InteractionHandType”中出现错误。。尽管我已经包括了“使用Microsoft.Kinect.Toolkit.Interaction”,但请有人帮忙~!你能解决这个问题吗?我在“InteractionHandType handType”上出错,它说它在命名空间中不存在。。请帮助我这里是我的问题: