首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Kinect SDK1.7更改KinectCursor图像和大小

Kinect SDK1.7更改KinectCursor图像和大小
EN

Stack Overflow用户
提问于 2013-06-27 17:35:00
回答 1查看 4K关注 0票数 5

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

  • ControlBasics WPF
  • InteractionGallery WPF.

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

我有一个要求,在这里,我想捕捉一个抓事件上的Kinect Tile Button。因为默认的KinectTileButton不提供抓地力事件。我在按钮上添加了一个抓地力事件处理程序。

代码语言:javascript
复制
KinectRegion.AddHandPointerGripHandler(kinectButton, OnHandPointerCaptured);

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

我在OnHandPointerCaptured方法中放置了一个调试断点,并且当我抓住KinectTileButton时能够收到适当的点击。但出于某种原因,我没有看到KinectCursor图像在KinectScrollViewer控件上发生变化。我尝试在isGripTarget类中设置KinectButtonBase属性,但没有帮助。

代码语言:javascript
复制
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图标更改为抓地力,以及大小。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-28 15:46:39

我发现-

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

代码语言:javascript
复制
  <Style TargetType="{x:Type local:KinectCursor}">

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

2) Tile Button上的抓地力事件- Kinect Button支持各种事件,这些事件可以根据您的愿望进行细分和操作。参见此Hand over button event in Kinect SDK 1.7

3)更改光标映像以抓取Tile Button - Microsoft.Kinect.Toolkit.Controls项目使用KinectCursorVisualizer.cs和KinectCursor.cs在UI上呈现虚拟手动游标。Open /Grip视觉状态是通过KinectCursor.cs中定义的这个依赖属性来控制的。

代码语言:javascript
复制
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

代码语言:javascript
复制
// Set open state
 cursor.IsOpen = !pointer.IsInGripInteraction;

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

代码语言:javascript
复制
  handPointer.IsInGripInteraction = newIsInGripInteraction;

如果您查看这一行上面的代码,您会发现,只有当目标元素定义了QueryInteractionStatusHandler并将args.Handled、args.IsInGripInteraction属性设置为true时,该属性才会设置为true。

因为KinectScrollViewer已经定义了这个处理程序,所以您可以看到一个抓地力图像。

代码语言:javascript
复制
 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)没有定义这个处理程序。

代码语言:javascript
复制
 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添加以下简单内容。可以添加到构造函数中。

代码语言:javascript
复制
//Add the handler
 KinectRegion.AddQueryInteractionStatusHandler(kinectButton, OnQuery);

定义Handler

代码语言:javascript
复制
 //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;
        }

您可能必须根据您的要求对此进行调整。快乐连接:)

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17349748

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档