-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDatabase.cs
executable file
·95 lines (77 loc) · 2.71 KB
/
Database.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.IO;
using System.Xml.Serialization;
using System.Drawing;
namespace Gestures
{
/*NOTE: Simply handles database while training*/
public class Database
{
public BindingList<string> Classes { get; private set; }
public BindingList<Sequence> Samples { get; private set; }
public Database()
{
Classes = new BindingList<string>();
Samples = new BindingList<Sequence>(); //Sequence class modified for 3D gesture sequence storage
}
public void Save(Stream stream)
{
var serializer = new XmlSerializer(typeof(BindingList<Sequence>));
serializer.Serialize(stream, Samples);
}
public void Load(Stream stream)
{
var serializer = new XmlSerializer(typeof(BindingList<Sequence>));
var samples = (BindingList<Sequence>)serializer.Deserialize(stream);
Classes.Clear();
foreach (string label in samples.First().Classes)
Classes.Add(label);
Samples.Clear();
foreach (Sequence sample in samples)
{
sample.Classes = Classes;
Samples.Add(sample);
}
}
//adds the GestureData obj and classLabel to database
public Sequence Add(GestureData[] sequence, string classLabel)
{
if (sequence == null || sequence.Length == 0)
return null;
if (!Classes.Contains(classLabel))
Classes.Add(classLabel);
int classIndex = Classes.IndexOf(classLabel);
//create a new obj of Sequence class, to add to the Samples<Sequence> list
Sequence sample = new Sequence()
{
Classes = Classes, //all the classes are stored in a list form
SourcePath = sequence, //the GestureData obj is added
Output = classIndex //the class label (int form)
};
Samples.Add(sample);
return sample;
}
public void Clear()
{
Classes.Clear();
Samples.Clear();
}
public int SamplesPerClass()
{
int min = 0;
foreach (string label in Classes)
{
int c = Samples.Count(p => p.OutputName == label);
if (min == 0)
min = c;
else if (c < min)
min = c;
}
return min;
}
}
}