add hand labels in draw

pull/293/head
Vladimir Mandic 2021-04-26 07:37:29 -04:00
parent 6e2d6dc40f
commit 3fe8807440
2 changed files with 22 additions and 9 deletions

View File

@ -9,7 +9,7 @@ Repository: **<git+https://github.com/vladmandic/human.git>**
## Changelog ## Changelog
### **HEAD -> main** 2021/04/25 mandic00@live.com ### **HEAD -> main** 2021/04/26 mandic00@live.com
- convert blazeface to module - convert blazeface to module
- version 1.8 release candidate - version 1.8 release candidate

View File

@ -410,11 +410,23 @@ export async function hand(inCanvas: HTMLCanvasElement, result: Array<any>, draw
} }
} }
} }
if (localOptions.drawLabels) {
const addHandLabel = (part, title) => {
ctx.fillStyle = localOptions.useDepth ? `rgba(${127.5 + (2 * part[part.length - 1][2])}, ${127.5 - (2 * part[part.length - 1][2])}, 255, 0.5)` : localOptions.color;
ctx.fillText(title, part[part.length - 1][0] + 4, part[part.length - 1][1] + 4);
};
ctx.font = localOptions.font;
addHandLabel(h.annotations.indexFinger, 'index');
addHandLabel(h.annotations.middleFinger, 'middle');
addHandLabel(h.annotations.ringFinger, 'ring');
addHandLabel(h.annotations.pinky, 'pinky');
addHandLabel(h.annotations.thumb, 'thumb');
addHandLabel(h.annotations.palmBase, 'palm');
}
if (localOptions.drawPolygons) { if (localOptions.drawPolygons) {
const addPart = (part) => { const addHandLine = (part) => {
if (!part) return; if (!part) return;
for (let i = 0; i < part.length; i++) { for (let i = 0; i < part.length; i++) {
ctx.lineWidth = localOptions.lineWidth;
ctx.beginPath(); ctx.beginPath();
ctx.strokeStyle = localOptions.useDepth ? `rgba(${127.5 + (2 * part[i][2])}, ${127.5 - (2 * part[i][2])}, 255, 0.5)` : localOptions.color; ctx.strokeStyle = localOptions.useDepth ? `rgba(${127.5 + (2 * part[i][2])}, ${127.5 - (2 * part[i][2])}, 255, 0.5)` : localOptions.color;
ctx.moveTo(part[i > 0 ? i - 1 : 0][0], part[i > 0 ? i - 1 : 0][1]); ctx.moveTo(part[i > 0 ? i - 1 : 0][0], part[i > 0 ? i - 1 : 0][1]);
@ -422,12 +434,13 @@ export async function hand(inCanvas: HTMLCanvasElement, result: Array<any>, draw
ctx.stroke(); ctx.stroke();
} }
}; };
addPart(h.annotations.indexFinger); ctx.lineWidth = localOptions.lineWidth;
addPart(h.annotations.middleFinger); addHandLine(h.annotations.indexFinger);
addPart(h.annotations.ringFinger); addHandLine(h.annotations.middleFinger);
addPart(h.annotations.pinky); addHandLine(h.annotations.ringFinger);
addPart(h.annotations.thumb); addHandLine(h.annotations.pinky);
// addPart(hand.annotations.palmBase); addHandLine(h.annotations.thumb);
// addPart(h.annotations.palmBase);
} }
} }
} }