|
@@ -15,6 +15,16 @@
|
|
|
/// </summary>
|
|
|
public partial class MainWindow : INotifyPropertyChanged
|
|
|
{
|
|
|
+
|
|
|
+ private bool open1 = false; //右手经过点位一
|
|
|
+ private bool open1a = false;
|
|
|
+ private bool open2 = false; //右手经过点位二
|
|
|
+ private bool open2a = false;
|
|
|
+ private bool open3 = false; //左手经过点位一
|
|
|
+ private bool open3a = false;
|
|
|
+ private bool open4 = false; //左手经过点位二
|
|
|
+ private bool open4a = false;
|
|
|
+ private int Count = 1;
|
|
|
// 活动的 Kinect 传感器
|
|
|
private KinectSensor _kinectSensor = null;
|
|
|
// 坐标映射器将一种类型的点映射到另一种
|
|
@@ -199,8 +209,10 @@
|
|
|
Joint jointHandLeft = joints[JointType.HandLeft];
|
|
|
//左肩
|
|
|
Joint jointShoulderLeft = joints[JointType.ShoulderLeft];
|
|
|
- // 脊柱中
|
|
|
+ //脊柱中
|
|
|
Joint jointSpineMid = joints[JointType.SpineBase];
|
|
|
+ //头
|
|
|
+ Joint jointHead = joints[JointType.Head];
|
|
|
|
|
|
|
|
|
//右手空间坐标
|
|
@@ -209,6 +221,15 @@
|
|
|
CameraSpacePoint positionHandLeft = jointHandLeft.Position;
|
|
|
//脊椎中空间坐标
|
|
|
CameraSpacePoint positionSpineMid = jointSpineMid.Position;
|
|
|
+ //头部空间坐标
|
|
|
+ CameraSpacePoint positionHead = jointHead.Position;
|
|
|
+ //左肩空间坐标
|
|
|
+ CameraSpacePoint positionShoulderLeft = jointShoulderLeft.Position;
|
|
|
+ //右肩空间坐标
|
|
|
+ CameraSpacePoint positionShoulderRight = jointShoulderRight.Position;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
//右手坐标集
|
|
|
float xHandRight = positionHandRight.X;
|
|
@@ -227,8 +248,8 @@
|
|
|
//追踪到所需目标。
|
|
|
|
|
|
|
|
|
- Console.WriteLine(body.HandRightState);
|
|
|
- Console.WriteLine(body.HandLeftState);
|
|
|
+ //Console.WriteLine(body.HandRightState);
|
|
|
+ //Console.WriteLine(body.HandLeftState);
|
|
|
//双手进入控制区域
|
|
|
if (body.HandRightState == HandState.Closed && body.HandLeftState == HandState.Closed && yHandRight > ySpineMid && yHandLeft > xSpineMid)
|
|
|
{
|
|
@@ -261,7 +282,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
+ //双手进入控制区域
|
|
|
if (body.HandRightState == HandState.Lasso && body.HandLeftState == HandState.Lasso && yHandRight > ySpineMid && yHandLeft > xSpineMid)
|
|
|
{
|
|
|
|
|
@@ -288,6 +309,82 @@
|
|
|
}
|
|
|
|
|
|
|
|
|
+ //麦克风管理
|
|
|
+ if (jointHead.TrackingState == TrackingState.Tracked
|
|
|
+ && jointHandRight.TrackingState == TrackingState.Tracked
|
|
|
+ && jointShoulderLeft.TrackingState == TrackingState.Tracked
|
|
|
+ && jointShoulderRight.TrackingState == TrackingState.Tracked)
|
|
|
+ {
|
|
|
+ if (positionHandRight.Y > positionHead.Y)
|
|
|
+ {
|
|
|
+ // Console.WriteLine("举过头顶");
|
|
|
+ if (positionHandRight.X < positionHead.X && positionHandRight.X > positionShoulderLeft.X)
|
|
|
+ {
|
|
|
+ //Console.WriteLine("手在左肩和头之间");
|
|
|
+ open2 = true;
|
|
|
+ open2a = true;
|
|
|
+ }
|
|
|
+ if (positionHandRight.X > positionShoulderRight.X)
|
|
|
+ {
|
|
|
+ // Console.WriteLine("右手在右肩之外");
|
|
|
+ open1 = true;
|
|
|
+ open1a = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (open1 == true && open2 == true)
|
|
|
+ {
|
|
|
+ if (positionHandRight.Y < positionHead.Y)
|
|
|
+ {
|
|
|
+ Console.WriteLine("手势合格,麦克风打开.键盘输入 下键");
|
|
|
+ open1 = false;
|
|
|
+ open2 = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ //Console.WriteLine("X = " + positionHead.X + ", Y = " + positionHead.Y + ", Z = " + positionHead.Z);
|
|
|
+ //Console.WriteLine("X = " + positionHandRight.X + ", Y = " + positionHandRight.Y + ", Z = " + positionHandRight.Z);
|
|
|
+ }
|
|
|
+
|
|
|
+ //麦克风关闭
|
|
|
+ if (jointHead.TrackingState == TrackingState.Tracked
|
|
|
+ && jointHandLeft.TrackingState == TrackingState.Tracked
|
|
|
+ && jointShoulderLeft.TrackingState == TrackingState.Tracked
|
|
|
+ && jointShoulderRight.TrackingState == TrackingState.Tracked)
|
|
|
+ {
|
|
|
+ if (positionHandLeft.Y > positionHead.Y)
|
|
|
+ {
|
|
|
+ // Console.WriteLine("举过头顶");
|
|
|
+ if (positionHead.X < positionHandLeft.X && positionHandLeft.X < positionShoulderRight.X)
|
|
|
+ {
|
|
|
+ // Console.WriteLine("左手在右肩与头之间");
|
|
|
+ open3 = true;
|
|
|
+ open3a = true;
|
|
|
+
|
|
|
+ }
|
|
|
+ if (positionHandLeft.X < positionShoulderLeft.X)
|
|
|
+ {
|
|
|
+ //Console.WriteLine("左手在左肩之外");
|
|
|
+ open4 = true;
|
|
|
+ open4a = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (open3 == true && open4 == true)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (positionHandLeft.Y < positionHead.Y)
|
|
|
+ {
|
|
|
+ Console.WriteLine("手势合格,麦克风关闭. 键盘输入 上键");
|
|
|
+
|
|
|
+ open3 = false;
|
|
|
+ open4 = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -295,6 +392,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
+ ////未使用功能 执行一次开启,再次重复关闭
|
|
|
+ if (open4 == true && open1 == true)
|
|
|
+ {
|
|
|
+ if (positionHandLeft.Y < positionHead.Y && positionHandRight.Y < positionHead.Y)
|
|
|
+ {
|
|
|
+ if (Count % 2 == 0)
|
|
|
+ {
|
|
|
+ Console.WriteLine("未知命令 执行 ");
|
|
|
+ open4 = false;
|
|
|
+ open1 = false;
|
|
|
+ Count++;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Console.WriteLine("未知命令 退出");
|
|
|
+ open4 = false;
|
|
|
+ open1 = false;
|
|
|
+ Count++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|