繁体   English   中英

Kinect SDK 1.7 | 更改KinectCursor图像和大小

[英]Kinect SDK 1.7 | Change KinectCursor image and size

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

  • ControlBasics WPF
  • InteractionGallery WPF。

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

我有一个要求,我想在Kinect平铺按钮上捕获一个抓握事件。 由于默认的KinectTileButton不提供Grip事件。 我在我的按钮上添加了一个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图标更改为grip,以及尺寸。

这是我发现的 -

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

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

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

2)Tile按钮上的抓握事件 - Kinect按钮支持各种可以根据您的需求进行操作和操作的事件。 请参阅Kinect SDK 1.7中的切换按钮事件

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM