-
Notifications
You must be signed in to change notification settings - Fork 0
/
CalibrationWindow.xaml.cs
55 lines (44 loc) · 1.61 KB
/
CalibrationWindow.xaml.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
using System.Windows;
using Microsoft.Kinect;
using System.IO;
using System.Collections.Generic;
using Newtonsoft.Json;
namespace Microsoft.Samples.Kinect.BodyBasics
{
/// <summary>
/// Logica di interazione per CalibrationWindow.xaml
/// </summary>
public partial class CalibrationWindow : Window
{
private KinectController kc;
private const string OPT_FILE = "calibration.json";
public CalibrationWindow()
{
InitializeComponent();
kc = new KinectController();
kc.bodyReader.FrameArrived += Calibration_FrameArrived;
}
private void Calibration_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
{
kc.Controller_FrameArrived(sender, e);
if (kc.Arm != ArmPointing.Nothing)
{
float pointedX = kc.GetPointedX();
float pointedY = kc.GetPointedY();
DataLog.Log(DataLog.DebugLevel.Message, "Calibrated with X=" + pointedX.ToString() +
" Y=" + pointedY.ToString());
if (!File.Exists(OPT_FILE))
File.Create(OPT_FILE).Close();
List<float> l = new List<float>();
l.Add(pointedX);
l.Add(pointedY);
StreamWriter cal_file = File.CreateText(OPT_FILE);
JsonTextWriter cal_writer = new JsonTextWriter(cal_file);
string data = JsonConvert.SerializeObject(l);
cal_writer.WriteRaw(data);
cal_file.Close();
this.Close();
}
}
}
}