微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

我正在破坏我的屁股以找到一种方法来检测某只手是否被关闭或打开.

我看到了Kinect for Windows Toolkit,但文档不存在,我找不到让它工作的方法.

有谁知道一种简单的方法来检测手的情况?如果它不涉及使用Kinect工具包的需要,那就更好了.

解决方法

这就是我最终做到的方式:

首先,我们需要一个看起来像这样的虚拟类:

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐