我已经下载了Kinect SDK 1.7
工具包,并使用了以下示例。
我发现Kinect Toolkit内部使用交互框架来检测手部位置/手势,并相应地将其映射到Kinect控件。
我有一个要求,我想在Kinect平铺按钮上捕获一个抓握事件。由于默认的KinectTileButton不提供Grip事件。我在我的按钮上添加了一个握柄事件处理程序。
KinectRegion.AddHandPointerGripHandler(kinectButton, OnHandPointerCaptured);
private void OnHandPointerCaptured(object sender, HandPointerEventArgs handPointerEventArgs)
{
// Add code here
}
我在OnHandPointerCaptured方法中放置了一个调试断点,并且当我抓住KinectTileButton时能够接收到正确的命中。但由于某种原因,我没有看到KinectCursor图像在KinectScrollViewer控件上发生变化。 我尝试在KinectButtonBase类中设置isGripTarget属性,但它没有帮助。
private void InitializeKinectButtonBase()
{
KinectRegion.AddHandPointerPressHandler(this, this.OnHandPointerPress);
KinectRegion.AddHandPointerGotCaptureHandler(this, this.OnHandPointerCaptured);
KinectRegion.AddHandPointerPressReleaseHandler(this, this.OnHandPointerPressRelease);
KinectRegion.AddHandPointerLostCaptureHandler(this, this.OnHandPointerLostCapture);
KinectRegion.AddHandPointerEnterHandler(this, this.OnHandPointerEnter);
KinectRegion.AddHandPointerLeaveHandler(this, this.OnHandPointerLeave);
// Use the same OnHandPointerPress handler for the grip event
KinectRegion.AddHandPointerGripHandler(this, this.OnHandPointerPress);
//Set Kinect button as Grip target
// KinectRegion.SetIsPressTarget(this, true);
KinectRegion.SetIsGripTarget(this, true);
}
如何将KinectCursor图像从左手图标更改为手柄,以及尺寸。
答案 0 :(得分:6)
这是我找到的 -
1)光标图像和大小 - 这两个示例都使用Microsoft.Kinect.Toolkit.Controls项目,该项目定义了这些示例中使用的自定义控件(KinectTileButton,KinectScrollViwer,KinectRegion等)。 Kinect光标图像和大小被定义为资源 Microsoft.Kinect.Toolkit.Controls - > Themes-> Generic.xaml。在文件中搜索以下内容 -
<Style TargetType="{x:Type local:KinectCursor}">
您可以根据需要进行修改。无法直接从UI中找到任何可以控制此属性/钩子的属性/钩子。
2)平铺按钮上的抓握事件 - Kinect按钮支持各种可以根据您的需求进行操作并根据您的需要采取行动的事件。看到这个 Hand over button event in Kinect SDK 1.7
3)将光标图像更改为平铺按钮上的Grip - Microsoft.Kinect.Toolkit.Controls项目使用KinectCursorVisualizer.cs和KinectCursor.cs在UI上呈现虚拟手形光标。 Open Hand / Grip可视状态通过KinectCursor.cs中定义的Dependency Property进行控制。
public static readonly DependencyProperty IsOpenProperty = DependencyProperty.Register(
"IsOpen",
typeof(bool),
typeof(KinectCursor),
new UIPropertyMetadata(true, (o, args) => ((KinectCursor)o).EnsureVisualState()));
快速查找属性上的所有引用IsOpen告诉我们设置此属性的唯一位置是KinectCursorVisualizer.cs-&gt; OnHandPointersUpdated方法。 Line-229
// Set open state
cursor.IsOpen = !pointer.IsInGripInteraction;
这个指针.IsInGripInteraction属性设置在KinectAdapter.cs第678行
handPointer.IsInGripInteraction = newIsInGripInteraction;
如果查看此行上方的代码,您会发现如果目标元素定义了QueryInteractionStatusHandler并且它设置了此属性,则此属性仅设置为true args.Handled,args.IsInGripInteraction属性为true。
由于KinectScrollViewer定义了此处理程序,因此您会看到一个夹点图像。
private void InitializeKinectScrollViewer()
{
KinectRegion.AddHandPointerGotCaptureHandler(this, this.OnHandPointerCaptured);
KinectRegion.AddHandPointerLostCaptureHandler(this, this.OnHandPointerLostCapture);
KinectRegion.AddHandPointerEnterHandler(this, this.OnHandPointerEnter);
KinectRegion.AddHandPointerMoveHandler(this, this.OnHandPointerMove);
KinectRegion.AddHandPointerPressHandler(this, this.OnHandPointerPress);
KinectRegion.AddHandPointerGripHandler(this, this.OnHandPointerGrip);
KinectRegion.AddHandPointerGripReleaseHandler(this, this.OnHandPointerGripRelease);
//This is the QueryInteractionStatusHandler
KinectRegion.AddQueryInteractionStatusHandler(this, this.OnQueryInteractionStatus);
KinectRegion.SetIsGripTarget(this, true);
this.scrollMoveTimer.Tick += this.OnScrollMoveTimerTick;
this.scrollViewerInertiaScroller.SlowEnoughForSelectionChanged += this.OnSlowEnoughForSelectionChanged;
// Create KinectRegion binding
this.kinectRegionBinder = new KinectRegionBinder(this);
this.kinectRegionBinder.OnKinectRegionChanged += this.OnKinectRegionChanged;
}
但是KinectTileButton(扩展KinectButtonBase)没有定义此处理程序
private void InitializeKinectButtonBase()
{
KinectRegion.AddHandPointerPressHandler(this, this.OnHandPointerPress);
KinectRegion.AddHandPointerGotCaptureHandler(this, this.OnHandPointerCaptured);
KinectRegion.AddHandPointerPressReleaseHandler(this, this.OnHandPointerPressRelease);
KinectRegion.AddHandPointerLostCaptureHandler(this, this.OnHandPointerLostCapture);
KinectRegion.AddHandPointerEnterHandler(this, this.OnHandPointerEnter);
KinectRegion.AddHandPointerLeaveHandler(this, this.OnHandPointerLeave);
KinectRegion.SetIsPressTarget(this, true);
}
如何定义此处理程序? - 简单地在UI上添加以下内容。可以添加到构造函数
//Add the handler
KinectRegion.AddQueryInteractionStatusHandler(kinectButton, OnQuery);
定义处理程序
//Variable to track GripInterationStatus
bool isGripinInteraction = false;
private void OnQuery(object sender, QueryInteractionStatusEventArgs handPointerEventArgs)
{
//If a grip detected change the cursor image to grip
if (handPointerEventArgs.HandPointer.HandEventType == HandEventType.Grip)
{
isGripinInteraction = true;
handPointerEventArgs.IsInGripInteraction = true;
}
//If Grip Release detected change the cursor image to open
else if (handPointerEventArgs.HandPointer.HandEventType == HandEventType.GripRelease)
{
isGripinInteraction = false;
handPointerEventArgs.IsInGripInteraction = false;
}
//If no change in state do not change the cursor
else if (handPointerEventArgs.HandPointer.HandEventType == HandEventType.None)
{
handPointerEventArgs.IsInGripInteraction = isGripinInteraction;
}
handPointerEventArgs.Handled = true;
}
您可能需要根据您的要求进行调整。 快乐运动:)