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

<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. SQLServer中同义词Synonym的用法

    以前一直认为SqlServer中的同义词(Synonym)没有什么用处,所以也一直没有去查它的语法格式.今天碰到一个问题,用Synonym来解决再好不过了.问题是这样子的,我的系统中用到了多个数据库, ...

  2. Scala之面向对象

    1. Scala基础练习 不使用str.toLong,str.toInt/Integer.valueOf()/Long.valueOf/Integer.parseInt()等,将字符串"12 ...

  3. Chrome Service Model

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

  4. NetBios, NetBios over TCP/IP, SMB 之间的关系

    首先提到的是NetBios,NetBios是Network Basic Input/Output System的缩写,提供了一种允许局域网内不同电脑能够通信的功能.严格来说,NetBios是一套API ...

  5. GIMP类似于PhotoShop的开源免费软件

    首先我们先看看他的界面如何,都有哪些功能!而且它支持多种平台,可以在MacOS.Windows.Linux操作系统上使用.非常值得推荐! ​ 1.官方地址下载地址: https://www.gimp. ...

  6. python 爬虫简介

    初识Python爬虫 互联网 简单来说互联网是由一个个站点和网络设备组成的大网,我们通过浏览器访问站点,站点把HTML.JS.CSS代码返回给浏览器,这些代码经过浏览器解析.渲染,将丰富多彩的网页呈现 ...

  7. Vue代理&跨域

    Vue 本地代理 纯前端技术解决跨域 vue-axios获取数据很多小伙伴都会使用,但如果前后端分离且后台没设置跨域许可,那要怎样才能解决跨域问题? 常用方法有几种: 通过jsonp跨域 通过修改do ...

  8. 【ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined) D】Tree

    [链接] 我是链接,点我呀:) [题意] 让你在树上找一个序列. 这个序列中a[1]=R 然后a[2],a[3]..a[d]它们满足a[2]是a[1]的祖先,a[3]是a[2]的祖先... 且w[a[ ...

  9. Get,Post和Head具体解释

    HTTP请求最经常使用的三个方法: (1)Get方法. 取回请求URL标志的不论什么信息,在浏览器的地址栏中输入网址的方式訪问网页时,浏览器採用GET方法向server获取资源. (2)Post方法. ...

  10. 在SSM框架中我设置拦截器filter不能通过注解获取到实现类

    我在用注解注入实现类的时候,出现了这样的错误:如以下截图: 这个地方报出的错误是说明我的一个接口类型的类没有获取到,后来我就想要是我的实现类没有获取到那么我就直接new一个实现类然后再进行调用就会出现 ...