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

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


I have downloaded Kinect SDK 1.7, toolkit and have played with following samples.

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

  • ControlBasics WPF
  • InteractionGallery WPF.

I figured out that Kinect Toolkit internally uses the interaction frame to detect the hand position/gesture and accordingly maps it with the Kinect Controls.

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

I have a requirement where I want to capture a grip event on a Kinect Tile Button. Since the default KinectTileButton does not provide a Grip event. I added a grip event handler on my button.

我有一个要求,我想在Kinect平铺按钮上捕获一个抓握事件。由于默认的KinectTileButton不提供Grip事件。我在我的按钮上添加了一个grip事件处理程序。

KinectRegion.AddHandPointerGripHandler(kinectButton, OnHandPointerCaptured);

private void OnHandPointerCaptured(object sender, HandPointerEventArgs handPointerEventArgs) 
{ 
    // Add code here
}

I placed a debug breakpoint inside the OnHandPointerCaptured method and was able to receive proper hits when I grip on the KinectTileButton. But for some reason I do not see the KinectCursor image change to a grip as it happens on the KinectScrollViewer control. I tried setting up the isGripTarget property in the KinectButtonBase class but it doesn't help.

我在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);                
}

How do I change the KinectCursor image from openhand icon to grip, and also the size.

如何将KinectCursor图像从openhand图标更改为grip,以及尺寸。

1 个解决方案

#1


6  

Here's what i found-

这是我发现的 -

1) Cursor Image and Size - Both these samples use Microsoft.Kinect.Toolkit.Controls project that defines the Custom Controls (KinectTileButton,KinectScrollViwer,KinectRegion etc.) used in these samples. The Kinect Cursor image and size is defined as a resource in Microsoft.Kinect.Toolkit.Controls ->Themes->Generic.xaml. Search for following in the file -

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

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

You can modify this as per your need. Wasn't able to find any properties/hooks exposed to control this directly from the UI.

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

2) Grip event on Tile Button - Kinect Button Supports various events which can be subsribed to and acted upon on your desire. see this Hand over button event in Kinect SDK 1.7

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

3) Change Cursor image to Grip on Tile Button - Microsoft.Kinect.Toolkit.Controls project uses KinectCursorVisualizer.cs and KinectCursor.cs to render the virtual hand cursor on the UI. The Open Hand/Grip visual state is controlled via this Dependency Property defined in KinectCursor.cs.

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()));

A quick find all references on the property IsOpen tells that the only place where this property is set is in KinectCursorVisualizer.cs-> OnHandPointersUpdated method. Line- 229

快速查找属性IsOpen的所有引用,告诉我们设置此属性的唯一位置是KinectCursorVisualizer.cs-> OnHandPointersUpdated方法。 229行

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

And this pointer.IsInGripInteraction property is set at KinectAdapter.cs Line 678

并且此pointer.IsInGripInteraction属性设置在KinectAdapter.cs第678行

  handPointer.IsInGripInteraction = newIsInGripInteraction;

If you look at the code just above this line you'll find that this property is only set to true if the target element has a QueryInteractionStatusHandler defined and it sets args.Handled , args.IsInGripInteraction property to true.

如果查看此行上方的代码,您会发现如果目标元素定义了QueryInteractionStatusHandler并且将args.Handled,args.IsInGripInteraction属性设置为true,则此属性仅设置为true。

Since KinectScrollViewer has this handler defined you see a grip image.

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

but KinectTileButton (extends KinectButtonBase) does not have this handler defined

但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);

        }

How to define this handler ? - Simple add following to your UI. Can be added to constructor

如何定义这个处理程序? - 简单地在UI中添加以下内容。可以添加到构造函数中

//Add the handler
 KinectRegion.AddQueryInteractionStatusHandler(kinectButton, OnQuery);

Define the Handler

定义处理程序

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

You may have to tweak this as per your requirement. Happy Kinecting :)

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

关注微信公众号

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2013/06/27/b6c8fe9371d6a00c67c2e5ebeb6008d8.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com