-
Notifications
You must be signed in to change notification settings - Fork 2
/
GestureResultView.cs
355 lines (307 loc) · 11.7 KB
/
GestureResultView.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
//------------------------------------------------------------------------------
// <copyright file="GestureResultView.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace Microsoft.Samples.Kinect.DiscreteGestureBasics
{
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Controls;
using WindowsInput;
/// <summary>
/// Stores discrete gesture results for the GestureDetector.
/// Properties are stored/updated for display in the UI.
/// </summary>
public sealed class GestureResultView : INotifyPropertyChanged
{
/// <summary> Image to show when the 'detected' property is true for a tracked body </summary>
private readonly ImageSource seatedImage = new BitmapImage(new Uri(@"Images\Seated.png", UriKind.Relative));
/// <summary> Image to show when the 'detected' property is false for a tracked body </summary>
private readonly ImageSource notSeatedImage = new BitmapImage(new Uri(@"Images\NotSeated.png", UriKind.Relative));
/// <summary> Image to show when the body associated with the GestureResultView object is not being tracked </summary>
private readonly ImageSource notTrackedImage = new BitmapImage(new Uri(@"Images\NotTracked.png", UriKind.Relative));
public float steerProgress = 0.0f;
/// <summary> Array of brush colors to use for a tracked body; array position corresponds to the body colors used in the KinectBodyView class </summary>
private readonly Brush[] trackedColors = new Brush[] { Brushes.Red, Brushes.Orange, Brushes.Green, Brushes.Blue, Brushes.Indigo, Brushes.Violet };
/// <summary> Brush color to use as background in the UI </summary>
private Brush bodyColor = Brushes.Gray;
/// <summary> The body index (0-5) associated with the current gesture detector </summary>
private int bodyIndex = 0;
/// <summary> Current confidence value reported by the discrete gesture </summary>
private float confidence = 0.0f;
/// <summary> True, if the discrete gesture is currently being detected </summary>
private bool detected = false;
/// <summary> Image to display in UI which corresponds to tracking/detection state </summary>
private ImageSource imageSource = null;
/// <summary> True, if the body is currently being tracked </summary>
private bool isTracked = false;
int count = 0;
private bool right = false;
private bool left = false;
private bool close = false;
//public static double volume = 0.0;
//MediaElement mediaElement;
/// <summary>
/// Initializes a new instance of the GestureResultView class and sets initial property values
/// </summary>
/// <param name="bodyIndex">Body Index associated with the current gesture detector</param>
/// <param name="isTracked">True, if the body is currently tracked</param>
/// <param name="detected">True, if the gesture is currently detected for the associated body</param>
/// <param name="confidence">Confidence value for detection of the 'Seated' gesture</param>
public GestureResultView(int bodyIndex, bool isTracked, bool detected, float confidence,float progress,bool right,bool left,bool close)
{
this.BodyIndex = bodyIndex;
this.IsTracked = isTracked;
this.Detected = detected;
this.Confidence = confidence;
this.ImageSource = this.notTrackedImage;
this.SteerProgress = progress;
this.right = right;
this.left = left;
this.close = close;
}
/// <summary>
/// INotifyPropertyChangedPropertyChanged event to allow window controls to bind to changeable data
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// Gets the body index associated with the current gesture detector result
/// </summary>
public int BodyIndex
{
get
{
return this.bodyIndex;
}
private set
{
if (this.bodyIndex != value)
{
this.bodyIndex = value;
this.NotifyPropertyChanged();
}
}
}
/// <summary>
/// Gets the body color corresponding to the body index for the result
/// </summary>
public Brush BodyColor
{
get
{
return this.bodyColor;
}
private set
{
if (this.bodyColor != value)
{
this.bodyColor = value;
this.NotifyPropertyChanged();
}
}
}
/// <summary>
/// Gets a value indicating whether or not the body associated with the gesture detector is currently being tracked
/// </summary>
public bool IsTracked
{
get
{
return this.isTracked;
}
private set
{
if (this.IsTracked != value)
{
this.isTracked = value;
this.NotifyPropertyChanged();
}
}
}
/// <summary>
/// Gets a value indicating whether or not the discrete gesture has been detected
/// </summary>
public bool Detected
{
get
{
return this.detected;
}
private set
{
if (this.detected != value)
{
this.detected = value;
this.NotifyPropertyChanged();
}
}
}
/// <summary>
/// Gets a float value which indicates the detector's confidence that the gesture is occurring for the associated body
/// </summary>
public float Confidence
{
get
{
return this.confidence;
}
private set
{
if (this.confidence != value)
{
this.confidence = value;
this.NotifyPropertyChanged();
}
}
}
public bool Right
{
get
{
return this.right;
}
private set
{
if (this.right != value)
{
this.right = value;
this.NotifyPropertyChanged();
}
}
}
public bool Close
{
get
{
return this.close;
}
private set
{
if (this.close != value)
{
this.close = value;
this.NotifyPropertyChanged();
}
}
}
public bool Left
{
get
{
return this.left;
}
private set
{
if (this.left != value)
{
this.left = value;
this.NotifyPropertyChanged();
}
}
}
/// <summary>
/// Gets an image for display in the UI which represents the current gesture result for the associated body
/// </summary>
public ImageSource ImageSource
{
get
{
return this.imageSource;
}
private set
{
if (this.ImageSource != value)
{
this.imageSource = value;
this.NotifyPropertyChanged();
}
}
}
public float SteerProgress
{
get
{
return this.steerProgress;
}
private set
{
if (this.SteerProgress != value)
{
this.steerProgress = value;
this.NotifyPropertyChanged();
}
}
}
/// <summary>
/// Updates the values associated with the discrete gesture detection result
/// </summary>
/// <param name="isBodyTrackingIdValid">True, if the body associated with the GestureResultView object is still being tracked</param>
/// <param name="isGestureDetected">True, if the discrete gesture is currently detected for the associated body</param>
/// <param name="detectionConfidence">Confidence value for detection of the discrete gesture</param>
public void UpdateGestureResult(bool isBodyTrackingIdValid, bool isGestureDetected, float detectionConfidence,float progress,bool right,bool left,bool close)
{
this.IsTracked = isBodyTrackingIdValid;
this.Confidence = 0.0f;
if (!this.IsTracked)
{
this.ImageSource = this.notTrackedImage;
this.Detected = false;
this.BodyColor = Brushes.Gray;
this.SteerProgress = -1.0f;
this.Right = false;
this.Left = false;
this.Close = false;
}
else
{
this.Detected = isGestureDetected;
this.SteerProgress = progress;
this.BodyColor = this.trackedColors[this.BodyIndex];
if (this.Detected)
{
this.Confidence = detectionConfidence;
this.ImageSource = this.seatedImage;
this.Right = right;
this.Left = left;
this.Close = close;
if (this.SteerProgress>=0.9||confidence>=0.9)
{
if(this.Right)
System.Windows.Forms.SendKeys.SendWait("{RIGHT}");
else if (this.Left)
System.Windows.Forms.SendKeys.SendWait("{LEFT}");
else if (this.Close)
{
System.Windows.Forms.SendKeys.SendWait("%{F4}");
}
System.Threading.Thread.Sleep(2500);
}
/*if(this.Confidence<=0.3)
{
count = 0;
}*/
}
else
{
this.ImageSource = this.notSeatedImage;
//count = 0;
}
}
}
/// <summary>
/// Notifies UI that a property has changed
/// </summary>
/// <param name="propertyName">Name of property that has changed</param>
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}