mirror of https://github.com/vladmandic/human
breaking changes to results.hand output properties
parent
d670fc4ad9
commit
33ba2bd266
|
@ -404,8 +404,8 @@ export async function hand(inCanvas: HTMLCanvasElement, result: Array<Hand>, dra
|
|||
ctx.stroke();
|
||||
}
|
||||
if (localOptions.drawPoints) {
|
||||
if (h.landmarks && h.landmarks.length > 0) {
|
||||
for (const pt of h.landmarks) {
|
||||
if (h.keypoints && h.keypoints.length > 0) {
|
||||
for (const pt of h.keypoints) {
|
||||
ctx.fillStyle = localOptions.useDepth ? `rgba(${127.5 + (2 * pt[2])}, ${127.5 - (2 * pt[2])}, 255, 0.5)` : localOptions.color;
|
||||
point(ctx, pt[0], pt[1], 0, localOptions);
|
||||
}
|
||||
|
|
|
@ -35,12 +35,12 @@ export async function predict(input, config): Promise<Hand[]> {
|
|||
}
|
||||
}
|
||||
|
||||
const landmarks = predictions[i].landmarks as unknown as Array<[number, number, number]>;
|
||||
const keypoints = predictions[i].landmarks as unknown as Array<[number, number, number]>;
|
||||
|
||||
let box: [number, number, number, number] = [Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, 0, 0]; // maximums so conditionals work
|
||||
let boxRaw: [number, number, number, number] = [0, 0, 0, 0];
|
||||
if (landmarks && landmarks.length > 0) { // if we have landmarks, calculate box based on landmarks
|
||||
for (const pt of landmarks) {
|
||||
if (keypoints && keypoints.length > 0) { // if we have landmarks, calculate box based on landmarks
|
||||
for (const pt of keypoints) {
|
||||
if (pt[0] < box[0]) box[0] = pt[0];
|
||||
if (pt[1] < box[1]) box[1] = pt[1];
|
||||
if (pt[0] > box[2]) box[2] = pt[0];
|
||||
|
@ -63,7 +63,7 @@ export async function predict(input, config): Promise<Hand[]> {
|
|||
(predictions[i].box.bottomRight[1] - predictions[i].box.topLeft[1]) / input.shape[1],
|
||||
];
|
||||
}
|
||||
hands.push({ id: i, confidence: Math.round(100 * predictions[i].confidence) / 100, box, boxRaw, landmarks, annotations });
|
||||
hands.push({ id: i, confidence: Math.round(100 * predictions[i].confidence) / 100, box, boxRaw, keypoints, annotations });
|
||||
}
|
||||
return hands;
|
||||
}
|
||||
|
|
|
@ -48,16 +48,16 @@ export function calc(newResult: Result): Result {
|
|||
.map((b, j) => ((bufferedFactor - 1) * bufferedResult.hand[i].box[j] + b) / bufferedFactor)) as [number, number, number, number];
|
||||
const boxRaw = (newResult.hand[i].boxRaw // update boxRaw
|
||||
.map((b, j) => ((bufferedFactor - 1) * bufferedResult.hand[i].boxRaw[j] + b) / bufferedFactor)) as [number, number, number, number];
|
||||
const landmarks = newResult.hand[i].landmarks // update landmarks
|
||||
const keypoints = newResult.hand[i].keypoints // update landmarks
|
||||
.map((landmark, j) => landmark
|
||||
.map((coord, k) => (((bufferedFactor - 1) * bufferedResult.hand[i].landmarks[j][k] + coord) / bufferedFactor)) as [number, number, number]);
|
||||
.map((coord, k) => (((bufferedFactor - 1) * bufferedResult.hand[i].keypoints[j][k] + coord) / bufferedFactor)) as [number, number, number]);
|
||||
const keys = Object.keys(newResult.hand[i].annotations); // update annotations
|
||||
const annotations = {};
|
||||
for (const key of keys) {
|
||||
annotations[key] = newResult.hand[i].annotations[key]
|
||||
.map((val, j) => val.map((coord, k) => ((bufferedFactor - 1) * bufferedResult.hand[i].annotations[key][j][k] + coord) / bufferedFactor));
|
||||
}
|
||||
bufferedResult.hand[i] = { ...newResult.hand[i], box, boxRaw, landmarks, annotations }; // shallow clone plus updated values
|
||||
bufferedResult.hand[i] = { ...newResult.hand[i], box, boxRaw, keypoints, annotations }; // shallow clone plus updated values
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ export interface Hand {
|
|||
confidence: number,
|
||||
box: [number, number, number, number],
|
||||
boxRaw: [number, number, number, number],
|
||||
landmarks: Array<[number, number, number]>,
|
||||
keypoints: Array<[number, number, number]>,
|
||||
annotations: Record<string, Array<[number, number, number]>>,
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue