-
Notifications
You must be signed in to change notification settings - Fork 2
/
modelGetData.js
62 lines (57 loc) · 2.46 KB
/
modelGetData.js
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
// A function to print the keypoints to console
function printKeypoints() {
// Loop through all the poses detected
for (let i = 0; i < poses.length; i++) {
// For each pose detected, loop through all the keypoints
for (let j = 0; j < poses[i].pose.keypoints.length; j++) {
// A keypoint is an object describing a body part (like rightArm or leftShoulder)
let keypoint = poses[i].pose.keypoints[j];
// Only draw an ellipse is the pose probability is bigger than the minimum confidence
if (keypoint.score > minConfidence) {
console.log(keypoint, keypoint.position.x, keypoint.position.y);
}
}
}
}
//function to get model data
function model_getPoseData() {
return poses;
}
//function to get a particular part's coordinate
//returns an array of[x, y] if the detection was above
//minConfidence
function model_getPartCoordinate(bodyPartName, minConfidence) {
// Loop through all the poses detected
for (let i = 0; i < poses.length; i++) {
// For each pose detected, loop through all the keypoints
for (let j = 0; j < poses[i].pose.keypoints.length; j++) {
// A keypoint is an object describing a body part (like rightArm or leftShoulder)
let keypoint = poses[i].pose.keypoints[j];
// Only draw an ellipse is the pose probability is bigger than the minimum confidence
if (keypoint.score > minConfidence && keypoint.part == bodyPartName) {
//get the element in the array for a chosen body part
return [keypoint.position, keypoint.score];
}
}
}
}
function getHeadY() {
if (model_getPartCoordinate("nose", minConfidence) != undefined) {
return model_getPartCoordinate("nose", minConfidence);
} else if (model_getPartCoordinate("leftEar", minConfidence) != undefined) {
return model_getPartCoordinate("leftEar", minConfidence);
} else if (model_getPartCoordinate("rightEar", minConfidence) != undefined) {
return model_getPartCoordinate("rightEar", minConfidence);
} else if (model_getPartCoordinate("leftEye", minConfidence) != undefined) {
return model_getPartCoordinate("leftEye", minConfidence);
} else if (model_getPartCoordinate("rightEye", minConfidence) != undefined) {
return model_getPartCoordinate("rightEye", minConfidence);
} else {
return undefined;
}
}
function getScore(listOfRepInfo){
for (var i = 0; i < listOfRepInfo.length; i++) {
console.log(listOfRepInfo[i]);
}
}