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

<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. js 字符串首字母转为大写 正则

    function replaceReg(str){ var reg = /\b(\w)|\s(\w)/g; str = str.toLowerCase(); return str.replace(re ...

  2. Ambari Confirm Hosts Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).

    Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).解决 Permanently added 'hdp21,192. ...

  3. UI Framework-1: Aura and Shell dependencies

    Aura and Shell dependencies The diagram below shows the dependencies of Chrome, Ash (Aura shell), vi ...

  4. MySql系列表之间的关系

    foreign key 快速理解foreign key   员工信息表有三个字段:工号  姓名  部门 公司有3个部门,但是有1个亿的员工,那意味着部门这个字段需要重复存储,部门名字越长,越浪费 数据 ...

  5. 装了ubuntu后笔记本电脑的无线网卡用不了,怎么设置?

    百度经验的一篇文章 http://jingyan.baidu.com/article/ca2d939dd4f1b4eb6c31ce09.html 点击右上角的齿轮,选择“系统设置”   点击“软件和更 ...

  6. 移动端开发ios和安卓兼容问题

    移动端开发ios和安卓兼容问题 最近做移动端混合开的时候遇到一些安卓和iOS的兼容性问题,兼容想问题不仅在浏览器存在也在APP开发当中也会经常遇到这样的情况. 最近看了一下内容很不错的移动端开发相关的 ...

  7. 【计算机视觉】基于Kalman滤波器的进行物体的跟踪

    预估器 我们希望能够最大限度地使用測量结果来预计移动物体的运动. 所以,多个測量的累积能够让我们检測出不受噪声影响的部分观測轨迹. 一个关键的附加要素即此移动物体运动的模型. 有了这个模型,我们不仅能 ...

  8. zzuli--1812--sort(模拟水题)

    1812: sort Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 158  Solved: 30 SubmitStatusWeb Board Des ...

  9. django 笔记3

    FBV function base view url.py index -> 函数名 view.py def 函数(requset): ... CBV class base view /inde ...

  10. Json 序列化以及反序列化的三种方式(二)

    1.什么是JSON? Json[javascript对象表示方法],它是一个轻量级的数据交换格式,我们可以很简单的来读取和写它,并且它很容易被计算机转化和生成,它是完全独立于语言的 2.Json支持下 ...