5

我已经下载Kinect SDK 1.7了工具包并使用了以下示例。

  • 控制基础 WPF
  • 交互画廊 WPF。

我发现 Kinect Toolkit 在内部使用交互框架来检测手的位置/手势,并相应地将其映射到 Kinect 控件。

我有一个需求,我想在 Kinect Tile Button 上捕获抓握事件。由于默认 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 图像从 openhand 图标更改为夹点,以及大小。

4

1 回答 1

7

这是我发现的-

1) 光标图像和大小- 这两个示例都使用 Microsoft.Kinect.Toolkit.Controls 项目,该项目定义了这些示例中使用的自定义控件(KinectTileButton、KinectScrollViwer、KinectRegion 等)。Kinect 光标图像和大小在 Microsoft.Kinect.Toolkit.Controls ->Themes->Generic.xaml 中定义为资源。在文件中搜索以下内容 -

  <Style TargetType="{x:Type local:KinectCursor}">

您可以根据需要进行修改。无法直接从 UI 中找到任何公开的属性/挂钩来控制它。

2) Tile Button 上的 Grip 事件- Kinect Button 支持各种事件,这些事件可以订阅并根据您的需要进行操作。在 Kinect SDK 1.7 中查看此 移交按钮事件

3) 将光标图像更改为 Grip on Tile Button - Microsoft.Kinect.Toolkit.Controls 项目使用 KinectCursorVisualizer.cs 和 KinectCursor.cs 在 UI 上呈现虚拟手形光标。Open Hand/Grip 视觉状态通过 KinectCursor.cs 中定义的此依赖属性进行控制。

public static readonly DependencyProperty IsOpenProperty = DependencyProperty.Register(
        "IsOpen",
        typeof(bool),
        typeof(KinectCursor),
        new UIPropertyMetadata(true, (o, args) => ((KinectCursor)o).EnsureVisualState()));

快速查找有关 IsOpen 属性的所有引用表明设置此属性的唯一位置是 KinectCursorVisualizer.cs-> OnHandPointersUpdated 方法。线 - 229

// Set open state
 cursor.IsOpen = !pointer.IsInGripInteraction;

这个 pointer.IsInGripInteraction 属性设置在 KinectAdapter.cs 第 678 行

  handPointer.IsInGripInteraction = newIsInGripInteraction;

如果您查看这一行上方的代码,您会发现只有在目标元素定义了 QueryInteractionStatusHandler 并将 args.Handled 、 args.IsInGripInteraction 属性设置为 true 时,此属性才设置为 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;
        }

您可能需要根据您的要求进行调整。快乐的 Kinecting :)

于 2013-06-28T15:46:39.310 回答