edit blazepose keypoints

pull/280/head
Vladimir Mandic 2021-11-19 16:11:03 -05:00
parent ff8f5968fb
commit c8f85ead30
4 changed files with 18 additions and 13 deletions

View File

@ -65,7 +65,7 @@
"@tensorflow/tfjs-layers": "^3.11.0",
"@tensorflow/tfjs-node": "^3.11.0",
"@tensorflow/tfjs-node-gpu": "^3.11.0",
"@types/node": "^16.11.7",
"@types/node": "^16.11.9",
"@types/offscreencanvas": "^2019.6.4",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0",

View File

@ -127,7 +127,8 @@ async function detectParts(input: Tensor, config: Config, outputSize: [number, n
for (let i = 0; i < indexes.length - 1; i++) {
const pt0 = keypoints.find((kpt) => kpt.part === indexes[i]);
const pt1 = keypoints.find((kpt) => kpt.part === indexes[i + 1]);
if (pt0 && pt1 && pt0.score > (config.body.minConfidence || 0) && pt1.score > (config.body.minConfidence || 0)) pt.push([pt0.position, pt1.position]);
// if (pt0 && pt1 && pt0.score > (config.body.minConfidence || 0) && pt1.score > (config.body.minConfidence || 0)) pt.push([pt0.position, pt1.position]);
if (pt0 && pt1) pt.push([pt0.position, pt1.position]);
}
annotations[name] = pt;
}

View File

@ -18,12 +18,12 @@ export const kpt: Array<string> = [
'rightElbow', // 14
'leftWrist', // 15
'rightWrist', // 16
'leftPalm', // 17
'rightPalm', // 18
'leftPinky', // 17
'rightPinky', // 18
'leftIndex', // 19
'rightIndex', // 20
'leftPinky', // 21
'rightPinky', // 22
'leftThumb', // 21
'rightThumb', // 22
'leftHip', // 23
'rightHip', // 24
'leftKnee', // 25
@ -36,10 +36,10 @@ export const kpt: Array<string> = [
'rightFoot', // 32
'bodyCenter', // 33
'bodyTop', // 34
'leftThumb', // 35
'leftHand', // 36
'rightThumb', // 37
'rightHand', // 38
'leftPalm', // 35 // z-coord not ok
'leftHand', // 36 // similar to wrist but z-coord not ok
'rightPalm', // 37 // z-coord not ok
'rightHand', // 38 // similar to wrist but z-coord not ok
];
export const connected: Record<string, string[]> = {
@ -48,7 +48,9 @@ export const connected: Record<string, string[]> = {
torso: ['leftShoulder', 'rightShoulder', 'rightHip', 'leftHip', 'leftShoulder'],
leftArm: ['leftShoulder', 'leftElbow', 'leftWrist', 'leftPalm'],
rightArm: ['rightShoulder', 'rightElbow', 'rightWrist', 'rightPalm'],
leftHand: [],
rightHand: [],
head: [],
leftHand: ['leftHand', 'leftPalm', 'leftPinky', 'leftPalm', 'leftIndex', 'leftPalm', 'leftThumb'],
rightHand: ['rightHand', 'rightPalm', 'rightPinky', 'rightPalm', 'rightIndex', 'rightPalm', 'rightThumb'],
leftEye: ['leftEyeInside', 'leftEye', 'leftEyeOutside'],
rightEye: ['rightEyeInside', 'rightEye', 'rightEyeOutside'],
mouth: ['leftMouth', 'rightMouth'],
};

View File

@ -353,6 +353,7 @@ export async function body(inCanvas: AnyCanvas, result: Array<BodyResult>, drawO
}
if (localOptions.drawPoints && result[i].keypoints) {
for (let pt = 0; pt < result[i].keypoints.length; pt++) {
if (!result[i].keypoints[pt].score || (result[i].keypoints[pt].score === 0)) continue;
ctx.fillStyle = localOptions.useDepth && result[i].keypoints[pt].position[2] ? `rgba(${127.5 + (2 * (result[i].keypoints[pt].position[2] || 0))}, ${127.5 - (2 * (result[i].keypoints[pt].position[2] || 0))}, 255, 0.5)` : localOptions.color;
point(ctx, result[i].keypoints[pt].position[0], result[i].keypoints[pt].position[1], 0, localOptions);
}
@ -360,6 +361,7 @@ export async function body(inCanvas: AnyCanvas, result: Array<BodyResult>, drawO
if (localOptions.drawLabels && result[i].keypoints) {
ctx.font = localOptions.font;
for (const pt of result[i].keypoints) {
if (!pt.score || (pt.score === 0)) continue;
ctx.fillStyle = localOptions.useDepth && pt.position[2] ? `rgba(${127.5 + (2 * pt.position[2])}, ${127.5 - (2 * pt.position[2])}, 255, 0.5)` : localOptions.color;
ctx.fillText(`${pt.part} ${Math.trunc(100 * pt.score)}%`, pt.position[0] + 4, pt.position[1] + 4);
}