forked from yeemachine/kalidokit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
349 lines (341 loc) · 9.79 KB
/
index.d.ts
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
declare module "kalidokit" {
type XYZ = Record<"x" | "y" | "z", number>;
/** Vector Math class. */
export class Vector {
static negative(a: Vector, b: Vector): Vector;
static add(a: Vector, b: Vector | number, c: Vector): Vector;
static subtract(a: Vector, b: Vector | number, c: Vector): Vector;
static multiply(a: Vector, b: Vector | number, c: Vector): Vector;
static divide(a: Vector, b: Vector | number, c: Vector): Vector;
static cross(a: Vector, b: Vector | number, c: Vector): Vector;
static unit(a: Vector, b: Vector): Vector;
static fromAngles(theta: number, phi: number): Vector;
static randomDirection(): Vector;
static min(a: Vector | XYZ, b: Vector | XYZ): Vector;
static max(a: Vector | XYZ, b: Vector | XYZ): Vector;
static lerp(a: Vector, b: Vector, fraction: number): Vector;
static lerp(a: number, b: number, fraction: number): number;
static fromArray(a: XYZ | [number, number, number]): Vector;
static angleBetween(a: Vector, b: Vector): number;
static angleBetweenVertices(a: Vector, b: Vector | number, c: Vector): void;
static distance(a: Vector, b: Vector, d: Vector): number;
static toDegrees(a: number): number;
static normalizeAngle(radians: number): number;
static normalizeRadians(radians: number): number;
static find2DAngle(cx: number, cy: number, ex: number, ey: number): number;
static findRotation(a: Vector, b: Vector, normalize?: boolean): Vector;
static rollPitchYaw(a: Vector, b: Vector, c: Vector): Vector;
static angleBetween3DCoords(
a: Vector | number,
b: Vector | number,
c: Vector | number
): number;
constructor(a: Vector | number[] | XYZ | number, b: number, c: number);
x: number;
y: number;
z: number;
negative(): Vector;
add(v: Vector | number): Vector;
subtract(v: Vector | number): Vector;
multiply(v: Vector | number): Vector;
divide(v: Vector | number): Vector;
equals(v: Vector): boolean;
dot(v: Vector): number;
cross(v: Vector): Vector;
length(): number;
distance(v: Vector, d?: number): number;
lerp(v: Vector, fraction: number): Vector;
unit(): Vector;
min(): number;
max(): number;
toAngles(): {
theta: number;
phi: number;
};
angleTo(a: Vector): number;
toArray(n: any): number[];
clone(): Vector;
init(x: number, y: number, z: number): Vector;
}
/** Class representing pose solver. */
export class Pose {
/** expose arm rotation calculator as a static method */
static calcArms: (lm: any[]) => {
UpperArm: {
r: Vector;
l: Vector;
};
LowerArm: {
r: Vector;
l: Vector;
};
Hand: {
r: Vector;
l: Vector;
};
Unscaled: {
UpperArm: {
r: Vector;
l: Vector;
};
LowerArm: {
r: Vector;
l: Vector;
};
Hand: {
r: Vector;
l: Vector;
};
};
};
/** expose hips position and rotation calculator as a static method */
static calcHips: (
lm3d: any[],
lm2d: any[]
) => {
Hips: any;
Spine: any;
};
/** expose leg rotation calculator as a static method */
static calcLegs: (lm: any[]) => {
UpperLeg: {
r: Vector;
l: Vector;
};
LowerLeg: {
r: Vector;
l: Vector;
};
Unscaled: {
UpperArm: {
r: Vector;
l: Vector;
};
LowerLeg: {
r: Vector;
l: Vector;
};
};
};
/**
* Combines arm, hips, and leg calcs into one method
* @param {Array} lm3d : array of 3D pose vectors from tfjs or mediapipe
* @param {Array} lm2d : array of 2D pose vectors from tfjs or mediapipe
* @param {String} runtime: set as either "tfjs" or "mediapipe"
* @param {HTMLVideoElement} video : video element or video selector string
* @param {Object} imageSize: manually set hight and width of prediction
* @param {Boolean} enableLegs: toggle calculation of legs
*/
static solve(
lm3d: any[],
lm2d: any[],
{
runtime,
video,
imageSize,
enableLegs,
}?: {
runtime?: string;
video?: HTMLVideoElement | null;
imageSize?: {
width: number;
height: number;
};
enableLegs?: boolean;
}
): {
RightUpperArm: Vector;
RightLowerArm: Vector;
LeftUpperArm: Vector;
LeftLowerArm: Vector;
RightHand: Vector;
LeftHand: Vector;
RightUpperLeg: Vector;
RightLowerLeg: Vector;
LeftUpperLeg: Vector;
LeftLowerLeg: Vector;
Hips: any;
Spine: any;
};
}
/** Class representing hand solver. */
export class Hand {
/**
* Calculates finger and wrist as euler rotations
* @param {Array} lm : array of 3D hand vectors from tfjs or mediapipe
* @param {String} side: "Left" or "Right"
*/
static solve(lm: any[], side?: string): {};
}
/** Class representing face solver. */
export class Face {
/** expose blink stabilizer as a static method */
static stabilizeBlink: (
eye: any,
headY: number,
{
enableWink,
maxRot,
}?: {
enableWink?: boolean;
maxRot?: number;
}
) => {
l: any;
r: any;
};
/**
* Combines head, eye, pupil, and eyebrow calcs into one method
* @param {Array} lm : array of results from tfjs or mediapipe
* @param {String} runtime: set as either "tfjs" or "mediapipe"
* @param {HTMLVideoElement} video : video element or video selector string
* @param {Object} imageSize: manually set hight and width of prediction
* @param {Boolean} smoothBlink: toggle smooth blink
* @param {Array} blinkSettings: remaps high and low values to 0 to 1
*/
static solve(
lm: any[],
{
runtime,
video,
imageSize,
smoothBlink,
blinkSettings,
}?: {
runtime?: string;
video?: HTMLVideoElement | null;
imageSize?: {
width: number;
height: number;
};
smoothBlink?: boolean;
blinkSettings?: number[];
}
): {
head: {
y: number;
x: number;
z: number;
width: any;
height: any;
position: any;
normalized: XYZ;
degrees: XYZ;
};
eye: {
l: number;
r: number;
};
brow: number;
pupil: {
x: number;
y: number;
};
mouth: {
x: number;
y: number;
shape: {
A: number;
E: number;
I: any;
O: number;
U: number;
};
};
};
}
export namespace Utils {
export function clamp(val: number, min: number, max: number): number;
export function remap(val: number, min: number, max: number): number;
/** A set of default pose values to serve as "rest" values */
export const RestingDefault: {
Face: {
eye: {
l: number;
r: number;
};
mouth: {
x: number;
y: number;
shape: {
A: number;
E: number;
I: number;
O: number;
U: number;
};
};
head: {
x: number;
y: number;
z: number;
width: number;
height: number;
position: XYZ;
};
brow: number;
pupil: {
x: number;
y: number;
};
};
Pose: {
RightUpperArm: XYZ;
LeftUpperArm: XYZ;
RightLowerArm: XYZ;
LeftLowerArm: XYZ;
LeftUpperLeg: XYZ;
RightUpperLeg: XYZ;
RightLowerLeg: XYZ;
LeftLowerLeg: XYZ;
LeftHand: XYZ;
RightHand: XYZ;
Spine: XYZ;
Hips: {
position: XYZ;
rotation: XYZ;
};
};
RightHand: {
RightWrist: XYZ;
RightRingProximal: XYZ;
RightRingIntermediate: {
x: number;
y: number;
z: number;
};
RightRingDistal: XYZ;
RightIndexProximal: XYZ;
RightIndexIntermediate: XYZ;
RightIndexDistal: XYZ;
RightMiddleProximal: XYZ;
RightMiddleIntermediate: XYZ;
RightMiddleDistal: XYZ;
RightThumbProximal: XYZ;
RightThumbIntermediate: XYZ;
RightThumbDistal: XYZ;
RightLittleProximal: XYZ;
RightLittleIntermediate: XYZ;
RightLittleDistal: XYZ;
};
LeftHand: {
LeftWrist: XYZ;
LeftRingProximal: XYZ;
LeftRingIntermediate: XYZ;
LeftRingDistal: XYZ;
LeftIndexProximal: XYZ;
LeftIndexIntermediate: XYZ;
LeftIndexDistal: XYZ;
LeftMiddleProximal: XYZ;
LeftMiddleIntermediate: XYZ;
LeftMiddleDistal: XYZ;
LeftThumbProximal: XYZ;
LeftThumbIntermediate: XYZ;
LeftThumbDistal: XYZ;
LeftLittleProximal: XYZ;
LeftLittleIntermediate: XYZ;
LeftLittleDistal: XYZ;
};
};
}
}