none
有没有有关SDK中关于PUSH手势的代码。。 RRS feed

答案

  •  

    您好,能够详细说明一下PUSH手势时什么动作吗?不知道您是否想要的是Push Button,就是将用鼠标单击按钮移植到Kinect上,原理比较简单,利用Kinect景深数据中人手部关节点的位置与Kinect的距离,如果小于某一阈值,即触发某一事件,代码如下:

    public class KinectButton:Button 
    { 
        public static readonlyRoutedEventKinectCursorEnterEvent = KinectInput.KinectCursorEnterEvent.AddOwner(typeof(KinectButton)); 
        public static readonlyRoutedEventKinectCursorLeaveEvent = KinectInput.KinectCursorLeaveEvent.AddOwner(typeof(KinectButton)); 
        public static readonlyRoutedEventKinectCursorMoveEvent = KinectInput.KinectCursorMoveEvent.AddOwner(typeof(KinectButton)); 
        public static readonlyRoutedEventKinectCursorActivatedEvent = KinectInput.KinectCursorActivatedEvent.AddOwner(typeof(KinectButton)); 
        public static readonlyRoutedEventKinectCursorDeactivatedEvent = KinectInput.KinectCursorDeactivatedEvent.AddOwner(typeof(KinectButton)); 
    
    
        public eventKinectCursorEventHandlerKinectCursorEnter 
        { 
            add{ base.AddHandler(KinectCursorEnterEvent, value); } 
            remove{ base.RemoveHandler(KinectCursorEnterEvent, value); } 
        } 
    
        public eventKinectCursorEventHandlerKinectCursorLeave 
        { 
            add{ base.AddHandler(KinectCursorLeaveEvent, value); } 
            remove{ base.RemoveHandler(KinectCursorLeaveEvent, value); } 
        } 
    
        public eventKinectCursorEventHandlerKinectCursorMove 
        { 
            add{ base.AddHandler(KinectCursorMoveEvent, value); } 
            remove{ base.RemoveHandler(KinectCursorMoveEvent, value); } 
        } 
    
        public eventRoutedEventHandlerKinectCursorActivated 
        { 
            add{ base.AddHandler(KinectCursorActivatedEvent, value); } 
            remove{ base.RemoveHandler(KinectCursorActivatedEvent, value); } 
        } 
    
        public eventRoutedEventHandlerKinectCursorDeactivated 
        { 
            add{ base.AddHandler(KinectCursorDeactivatedEvent, value); } 
            remove{ base.RemoveHandler(KinectCursorDeactivatedEvent, value); } 
        } 
    }
    
    public class PushButton:KinectButton
    {
        protected double handDepth;
        public double PushThreshold
        {
            get { return (double)GetValue(PushThresholdProperty); }
            set { SetValue(PushThresholdProperty, value); }
        }
    
        public static readonly DependencyProperty PushThresholdProperty =
            DependencyProperty.Register("PushThreshold", typeof(double), typeof(PushButton), new UIPropertyMetadata(100d));
    
        protected override void OnKinectCursorMove(object sender, KinectCursorEventArgs e)
        {
            if (e.Z < handDepth - PushThreshold)
            {
                RaiseEvent(new RoutedEventArgs(ClickEvent));
            }
        }
    
        protected override void OnKinectCursorEnter(object sender, KinectCursorEventArgs e)
        {
            handDepth = e.Z;
        }
    }

    更多细节您可以查看这边文章 http://www.cnblogs.com/yangecnu/archive/2012/04/28/KinectSDK_GesturesDetection_part2_BasicGesturesDetection.html

       另外,在Kinect  Developer Toolkit 1.7.0 中有 InteractionGallery-WPF C# Sample,您可以尝试看下这个里面的代码。  

       K4W 1.7 SDK中也有PushButton相关的例子,您可以参考 http://social.msdn.microsoft.com/Forums/zh-CN/a2b67676-d2d2-4319-a2d7-6e332778a217/kinect-interaction 


    2013年7月2日 1:07
    版主