-
Notifications
You must be signed in to change notification settings - Fork 66
/
KeyPointSetup.cs
182 lines (176 loc) · 6.07 KB
/
KeyPointSetup.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
using System.Collections.Generic;
using YoloDotNet.Models;
namespace ConsoleDemo.Config
{
/// <summary>
/// Demonstrates configuring a custom keypoint marker profile with custom colors and illustrating keypoint connections.
/// </summary>
public static class CustomKeyPointColorMap
{
/// <summary>
/// Keypoints must be in the same EXACT order(!) as in the trained model.
/// </summary>
private enum KeyPointType
{
Nose,
LeftEye,
RightEye,
LeftEar,
RightEar,
LeftShoulder,
RightShoulder,
LeftElbow,
RightElbow,
LeftWrist,
RightWrist,
LeftHip,
RightHip,
LeftKnee,
RightKnee,
LeftAnkle,
RightAnkle
}
/// <summary>
/// Color names for identifying hexadecimal colors
/// </summary>
private enum KeyPointColor
{
Green,
LightBlue,
Yellow,
HotPink
}
/// <summary>
/// Named hexadecimal colors
/// </summary>
private static Dictionary<KeyPointColor, string> Colors => new()
{
{ KeyPointColor.Green, "#A2FF33" }, // Light green
{ KeyPointColor.LightBlue, "#33ACFF" }, // Light blue
{ KeyPointColor.Yellow, "#FFF633" }, // Yellow
{ KeyPointColor.HotPink, "#FF33AC" } // Hot pink
};
/// <summary>
/// Keypoint options.
/// </summary>
public static KeyPointOptions KeyPointOptions => new()
{
PoseConfidence = 0.65,
PoseMarkers = GetPoseMarkerConfiguration,
DrawBoundingBox = true
};
#region Method for configuring custom keypoints and their connections
/// <summary>
/// Configure keypoint-connections and what colors to use.
/// </summary>
private static KeyPointMarker[] GetPoseMarkerConfiguration =>
[
new () // Nose
{
Color = Colors[KeyPointColor.Green],
Connections =
[
new ((int)KeyPointType.LeftEye, Colors[KeyPointColor.Green]),
new ((int)KeyPointType.RightEye, Colors[KeyPointColor.Green])
]
},
new () // Left eye
{
Color = Colors[KeyPointColor.Green],
Connections = [ new ((int)KeyPointType.RightEye, Colors[KeyPointColor.Green]) ]
},
new () // Right eye
{
Color = Colors[KeyPointColor.Green],
},
new () // Left ear
{
Color = Colors[KeyPointColor.Green],
Connections =
[
new ((int)KeyPointType.LeftEye, Colors[KeyPointColor.Green]),
new ((int)KeyPointType.LeftShoulder, Colors[KeyPointColor.Green]),
]
},
new () // Right ear
{
Color = Colors[KeyPointColor.Green],
Connections =
[
new ((int)KeyPointType.RightEye, Colors[KeyPointColor.Green]),
new ((int)KeyPointType.RightShoulder, Colors[KeyPointColor.Green]),
]
},
new () // Left shoulder
{
Color = Colors[KeyPointColor.LightBlue],
Connections =
[
new ((int)KeyPointType.RightShoulder, Colors[KeyPointColor.LightBlue]),
new ((int)KeyPointType.LeftElbow, Colors[KeyPointColor.LightBlue]),
new ((int)KeyPointType.LeftHip, Colors[KeyPointColor.HotPink])
]
},
new () // Right shoulder
{
Color = Colors[KeyPointColor.LightBlue],
Connections =
[
new ((int)KeyPointType.RightElbow, Colors[KeyPointColor.LightBlue]),
new ((int)KeyPointType.RightHip, Colors[KeyPointColor.HotPink])
]
},
new () // Left elbow
{
Color = Colors[KeyPointColor.LightBlue],
Connections = [ new ((int)KeyPointType.LeftWrist, Colors[KeyPointColor.LightBlue]) ]
},
new () // Right elbow
{
Color = Colors[KeyPointColor.LightBlue],
Connections = [ new ((int)KeyPointType.RightWrist, Colors[KeyPointColor.LightBlue]) ]
},
new () // Left wrist
{
Color = Colors[KeyPointColor.LightBlue]
},
new () // Right wrist
{
Color = Colors[KeyPointColor.LightBlue]
},
new () // Left hip
{
Color = Colors[KeyPointColor.Yellow],
Connections =
[
new ((int)KeyPointType.RightHip, Colors[KeyPointColor.HotPink]),
new ((int)KeyPointType.LeftKnee, Colors[KeyPointColor.Yellow])
]
},
new () // Right hip
{
Color = Colors[KeyPointColor.Yellow],
Connections = [ new ((int)KeyPointType.RightKnee, Colors[KeyPointColor.Yellow]) ]
},
new () // Left knee
{
Color = Colors[KeyPointColor.Yellow],
Connections = [ new ((int)KeyPointType.LeftAnkle, Colors[KeyPointColor.Yellow]) ]
},
new () // Right knee
{
Color = Colors[KeyPointColor.Yellow],
Connections = [ new ((int)KeyPointType.RightAnkle, Colors[KeyPointColor.Yellow]) ]
},
new () // Left ankle
{
Color = Colors[KeyPointColor.Yellow]
},
new () // Right ankle
{
Color = Colors[KeyPointColor.Yellow]
}
];
#endregion
}
}