This repository has been archived by the owner on Jun 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Calibration.cs.scratch
127 lines (104 loc) · 3.87 KB
/
Calibration.cs.scratch
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
using Microsoft.Kinect;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GesturalMusic
{
class Calibration
{
KinectSensor kinectSensor;
ColorFrameReader colorFrameReader;
bool calibrated = false;
bool calibrating = false;
bool goTime = false;
public Calibration()
{
}
public void Start()
{
this.calibrating = true;
AlignmentCube.Transform = new ScaleTransform3D(1, 1, 1);
}
public void Calibrate()
{
Console.WriteLine("Calibrating...");
if (this.kinectSensor == null)
{
this.kinectSensor = KinectSensor.GetDefault();
}
this.colorFrameReader = this.kinectSensor.ColorFrameSource.OpenReader();
if (this.colorFrameReader != null)
{
this.colorFrameReader.FrameArrived += this.Reader_FrameArrived;
}
}
private void Reader_FrameArrived(object sender, ColorFrameArrivedEventArgs e)
{
if (this.calibrated)
{
this.EndCalibration();
}
using (ColorFrame colorFrame = e.FrameReference.AcquireFrame())
{
if (colorFrame != null)
{
var bitmap = colorFrame.ToBitmap();
//bitmap.Save("test.bmp");
//screen.Source = bitmap; // Display
if (this.goTime)
{
System.Windows.Media.Imaging.BitmapEncoder encoder = new System.Windows.Media.Imaging.BmpBitmapEncoder();
encoder.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(bitmap));
System.IO.MemoryStream ms = new System.IO.MemoryStream();
encoder.Save(ms);
System.Drawing.Bitmap b = new System.Drawing.Bitmap(ms);
Emgu.CV.Image<Bgr, Byte> imageFrame = new Image<Bgr, Byte>(b);
//// ----------------------------------------------------------------------
System.Drawing.Size patternSize = new System.Drawing.Size(6, 6);
Emgu.CV.Util.VectorOfPoint corners = new Emgu.CV.Util.VectorOfPoint();
bool test = CvInvoke.FindChessboardCorners(imageFrame, patternSize, corners);
Console.WriteLine("Calibration Success: " + test);
foreach (System.Drawing.Point cornerPoint in corners.ToArray())
{
Console.WriteLine(cornerPoint.X + ", " + cornerPoint.Y);
}
Console.WriteLine();
this.calibrated = true;
}
}
}
}
private void EndCalibration()
{
AlignmentCube.Transform = new ScaleTransform3D(0, 0, 0);
this.calibrating = false;
this.calibrated = true;
this.CloseKinect();
Console.WriteLine("Calibration complete.");
}
private void CloseKinect()
{
if (this.colorFrameReader != null)
{
this.colorFrameReader.Dispose();
this.colorFrameReader = null;
}
if (this.kinectSensor != null)
{
this.kinectSensor.Close();
this.kinectSensor = null;
}
}
private void CalibrateButton_Click(object sender, RoutedEventArgs e)
{
this.calibration
this.Calibrate();
}
private void FloorWindow_Closing(object sender, CancelEventArgs e)
{
this.CloseKinect();
}
}
}