我最近开始使用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 } } } } } }