基本注释都写了,就不废话了

<Window x:Class="KinectBasicHandTrackingFrameworkTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="600" Width="800" xmlns:my="clr-namespace:KinectBasicHandTrackingFramework;assembly=KinectBasicHandTrackingFramework">
<Grid Background="#CCFFFF">
<!--自定义控件-->
<my:KinectButton Content="Kinect Button" Height="130" Width="130" HorizontalAlignment="Left" Margin="576,51,0,0" Name="kinectButton1" VerticalAlignment="Top" Click="Button_Click" Background="Red" KinectCursorLeave="Button_KinectCursorLeave" />
<my:HoverButton Content="Hover Button" Height="130" Width="130" HorizontalAlignment="Left" Margin="576,227,0,0" Name="hoverButton1" VerticalAlignment="Top" Click="Button_Click" Background="Red" KinectCursorLeave="Button_KinectCursorLeave"/>
<my:MagnetButton Content="Magnet Button" Height="130" Width="130" HorizontalAlignment="Left" Margin="576,395,0,0" Name="magnetButton1" VerticalAlignment="Top" Click="Button_Click" Background="Red" KinectCursorLeave="Button_KinectCursorLeave" />
<ListBox Height="306" HorizontalAlignment="Left" Margin="46,51,0,0" Name="listBox1" VerticalAlignment="Top" Width="296" />
</Grid>
</Window>

namespace KinectBasicHandTrackingFrameworkTest
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private KinectSensor _kinectDevice;
private Skeleton[] _FrameSkeletons;
private WaveGesture _WaveGesture; // 此应用程序只能识别这一个手势,有待添加 public MainWindow()
{
InitializeComponent();
this._WaveGesture = new WaveGesture();
this._WaveGesture.GestureDetected += new EventHandler(_WaveGesture_GestureDetected); // 绑定事件,可以检测wave动作
this._kinectDevice = KinectSensor.KinectSensors.FirstOrDefault(x => x.Status == KinectStatus.Connected);
this._kinectDevice.SkeletonFrameReady += KinectDevice_SkeletonFrameReady;
} private void Button_Click(object sender, RoutedEventArgs e)
{
var button = sender as KinectButton; // 重写点击方法
button.Background = new SolidColorBrush(Colors.Green);
} private void Button_KinectCursorLeave(object sender, KinectCursorEventArgs e)
{
var button = sender as KinectButton;
button.Background = new SolidColorBrush(Colors.Red);
} private void KinectDevice_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
{
using (SkeletonFrame frame = e.OpenSkeletonFrame())
{
if (frame != null)
{
this._FrameSkeletons = new Skeleton[_kinectDevice.SkeletonStream.FrameSkeletonArrayLength];
frame.CopySkeletonDataTo(this._FrameSkeletons); DateTime startMarker = DateTime.Now; // 时间戳
this._WaveGesture.Update(this._FrameSkeletons, frame.Timestamp);
}
}
} private void _WaveGesture_GestureDetected(object sender, EventArgs e)
{
listBox1.Items.Add(string.Format("Wave Detected {0}", DateTime.Now.ToLongTimeString())); }
}
}

namespace KinectBasicHandTrackingFrameworkTest
{
public class WaveGesture
{
#region Member Variables
private const float WAVE_THRESHOLD = 0.1f;
private const int WAVE_MOVEMENT_TIMEOUT = ;
private const int LEFT_HAND = ;
private const int RIGHT_HAND = ;
private const int REQUIRED_ITERATIONS = ; private WaveGestureTracker[,] _PlayerWaveTracker = new WaveGestureTracker[, ]; public event EventHandler GestureDetected; // 表示将处理不包含事件数据的事件的方法
#endregion Member Variables #region Methods
public void Update(Skeleton[] skeletons, long frameTimestamp)
{
if (skeletons != null)
{
Skeleton skeleton; for (int i = ; i < skeletons.Length; i++)
{
skeleton = skeletons[i]; if (skeleton.TrackingState != SkeletonTrackingState.NotTracked)
{
TrackWave(skeleton, true, ref this._PlayerWaveTracker[i, LEFT_HAND], frameTimestamp); // 六个人分别检测左右手是否挥动
TrackWave(skeleton, false, ref this._PlayerWaveTracker[i, RIGHT_HAND], frameTimestamp);
}
else
{
this._PlayerWaveTracker[i, LEFT_HAND].Reset();
this._PlayerWaveTracker[i, RIGHT_HAND].Reset();
}
}
}
} private void TrackWave(Skeleton skeleton, bool isLeft, ref WaveGestureTracker tracker, long timestamp)
{
JointType handJointId = (isLeft) ? JointType.HandLeft : JointType.HandRight;
JointType elbowJointId = (isLeft) ? JointType.ElbowLeft : JointType.ElbowRight;
Joint hand = skeleton.Joints[handJointId];
Joint elbow = skeleton.Joints[elbowJointId]; if (hand.TrackingState != JointTrackingState.NotTracked && elbow.TrackingState != JointTrackingState.NotTracked)
{
if (tracker.State == WaveGestureState.InProgress && tracker.Timestamp + WAVE_MOVEMENT_TIMEOUT < timestamp) // 超过规定时间仍未完成
{
tracker.UpdateState(WaveGestureState.Failure, timestamp);
System.Diagnostics.Debug.WriteLine("Fail!");
}
else if (hand.Position.Y > elbow.Position.Y)
{
//Using the raw values where (0, 0) is the middle of the screen. From the user's perspective, the X-Axis grows more negative left and more positive right.
// 右手坐标系,Z轴射出,Y轴向上,X轴向左,坐标系的单位为米
if (hand.Position.X <= elbow.Position.X - WAVE_THRESHOLD)
{
tracker.UpdatePosition(WavePosition.Left, timestamp);
}
else if (hand.Position.X >= elbow.Position.X + WAVE_THRESHOLD)
{
tracker.UpdatePosition(WavePosition.Right, timestamp);
}
else
{
tracker.UpdatePosition(WavePosition.Neutral, timestamp);
} if (tracker.State != WaveGestureState.Success && tracker.IterationCount == REQUIRED_ITERATIONS)
{
tracker.UpdateState(WaveGestureState.Success, timestamp); // 重置
System.Diagnostics.Debug.WriteLine("Success!"); if (GestureDetected != null)
{
GestureDetected(this, new EventArgs());
}
}
}
else
{
if (tracker.State == WaveGestureState.InProgress)
{
tracker.UpdateState(WaveGestureState.Failure, timestamp);
System.Diagnostics.Debug.WriteLine("Fail!");
}
else
{
tracker.Reset();
}
}
}
else
{
// 关节点未成功跟踪,重置
tracker.Reset();
}
}
#endregion Methods #region Helper Objects
private enum WavePosition
{
None = ,
Left = ,
Right = ,
Neutral =
} private enum WaveGestureState
{
None = ,
Success = ,
Failure = ,
InProgress =
} private struct WaveGestureTracker
{
public int IterationCount;
public WaveGestureState State;
public long Timestamp;
public WavePosition StartPosition;
public WavePosition CurrentPosition; public void UpdateState(WaveGestureState state, long timestamp)
{
State = state;
Timestamp = timestamp;
} public void Reset()
{
IterationCount = ;
State = WaveGestureState.None;
Timestamp = ;
StartPosition = WavePosition.None;
CurrentPosition = WavePosition.None;
} public void UpdatePosition(WavePosition position, long timestamp)
{
if (CurrentPosition != position)
{
if (position == WavePosition.Left || position == WavePosition.Right)
{
if (State != WaveGestureState.InProgress)
{ // 若向左或向右但不是处理状态(None ,Success ,Failure) ,则重置
State = WaveGestureState.InProgress;
IterationCount = ;
StartPosition = position;
} IterationCount++; // 挥手过程中状态改变,迭代数++
} CurrentPosition = position; // 状态重置
Timestamp = timestamp;
}
}
}
#endregion Helper Objects
}
}

Kinect 开发 —— WaveHand的更多相关文章

  1. Kinect开发文章目录

    整理了一下去年为止到现在写的和翻译的Kinect的相关文章,方便大家查看.另外,最近京东上微软在搞活动, 微软 Kinect for Windows 京东十周年专供礼包 ,如果您想从事Kinect开发 ...

  2. Kinect开发资源汇总

    Kinect开发资源汇总   转自: http://www.sigvc.org/bbs/forum.php?mod=viewthread&tid=254&highlight=kinec ...

  3. Kinect开发学习笔记之(一)Kinect介绍和应用

    Kinect开发学习笔记之(一)Kinect介绍和应用 zouxy09@qq.com http://blog.csdn.net/zouxy09 一.Kinect简单介绍 Kinectfor Xbox ...

  4. Kinect开发笔记之二Kinect for Windows 2.0新功能

    这是本博客翻译文档的第一篇文章.笔者已经苦逼的竭尽全力的在翻译了.但无奈英语水平也是非常有限.不正确或者不妥当不准确的地方必定会有,还恳请大家留言或者邮件我以批评指正.我会虚心接受. 谢谢大家.   ...

  5. Kinect 开发 —— 杂一

    Kinect 提供了非托管(C++)和托管(.NET)两种开发方式的SDK,如果您用C++开发的话,需要安装Speech Runtime(V11),Kinect for Windows Runtime ...

  6. Kinect 开发 —— 控制PPT播放

    实现Kinect控制幻灯片播放很简单,主要思路是:使用Kinect捕捉人体动作,然后根据识别出来的动作向系统发出点击向前,向后按键的事件,从而使得幻灯片能够切换. 这里的核心功能在于手势的识别,我们在 ...

  7. Kinect 开发 —— 全息图

    Kinect的另一个有趣的应用是伪全息图(pseudo-hologram).3D图像可以根据人物在Kinect前面的各种位置进行倾斜和移动.如果方法够好,可以营造出3D控件中3D图像的效果,这样可以用 ...

  8. Kinect 开发 —— 进阶指引(上)

    本文将会介绍一些第三方类库如何来帮助处理Kinect传感器提供的数据.使用不同的技术进行Kinect开发,可以发掘出Kinect应用的强大功能.另一方面如果不使用这些为了特定处理目的而开发的一些类库, ...

  9. Kinect开发 —— 基础知识

    转自:http://www.cnblogs.com/yangecnu/archive/2012/04/02/KinectSDK_Application_Fundamentals_Part2.html ...

随机推荐

  1. Monad的基本运算

    A monad is created by defining a type constructor M and two operations, bind and return (where retur ...

  2. Chrome Service Model

    Chrome Service Model John Abd-El-Malek February 2016 Objective Move Chrome codebase towards a servic ...

  3. Codeforces#441 Div.2 四小题

    Codeforces#441 Div.2 四小题 链接 A. Trip For Meal 小熊维尼喜欢吃蜂蜜.他每天要在朋友家享用N次蜂蜜 , 朋友A到B家的距离是 a ,A到C家的距离是b ,B到C ...

  4. Win10平台下通过VMware虚拟机安装Win7、Ubuntu、Mac

    1.安装VMware14.1.1 下载地址:https://download.csdn.net/download/jasonczy/10611423 产品秘钥: CG54H-D8D0H-H8DHY-C ...

  5. ArcGIS 空间查询

    public static bool QueryMessPoint(IActiveView activeView, IFeatureClass featureClass, string whereCl ...

  6. Codeforces 528A Glass Carving STL模拟

    题目链接:点击打开链接 题意: 给定n*m的矩阵.k个操作 2种操作: 1.H x 横向在x位置切一刀 2.V y 竖直在y位置切一刀 每次操作后输出最大的矩阵面积 思路: 由于行列是不相干的,所以仅 ...

  7. 火狐浏览器设置bypass

    http://blog.sina.com.cn/s/blog_6f7d179e0101a60l.html 某个网段不使用代理的设置FF和IE不同,IE是用*通配符,FF是用CIDR的表示法, FF的简 ...

  8. centos 项目上线shell脚本

    最近在弄项目上线,然后写了个上线,备份,回滚的shell脚本 上线可根据自己公司项目做相关操作,备份回滚可修改目录则可实现 主管要求用shell写,那就用shell写吧 本想Python写更好的 哈哈 ...

  9. 最长回文子串 hihocode 1032 hdu 3068

    最长回文 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  10. Aspose.Cells相应操作及下载

    Aspose.Cells相应操作 1,上传 1.1 Workbook Workbook workBook = new Workbook(); 属性: 名称 值类型 说明 Colors Color[] ...