mirror of https://github.com/vladmandic/human
add body 3d interpolation
parent
c8f85ead30
commit
20cb91739d
|
@ -64,15 +64,23 @@ function calculateBoxes(keypoints: Array<BodyKeypoint>, outputSize: [number, num
|
||||||
async function prepareImage(input: Tensor): Promise<Tensor> {
|
async function prepareImage(input: Tensor): Promise<Tensor> {
|
||||||
const t: Record<string, Tensor> = {};
|
const t: Record<string, Tensor> = {};
|
||||||
if (!input.shape || !input.shape[1] || !input.shape[2]) return input;
|
if (!input.shape || !input.shape[1] || !input.shape[2]) return input;
|
||||||
padding = [
|
let final: Tensor;
|
||||||
[0, 0], // dont touch batch
|
if (input.shape[1] !== input.shape[2]) { // only pad if width different than height
|
||||||
[input.shape[2] > input.shape[1] ? Math.trunc((input.shape[2] - input.shape[1]) / 2) : 0, input.shape[2] > input.shape[1] ? Math.trunc((input.shape[2] - input.shape[1]) / 2) : 0], // height before&after
|
padding = [
|
||||||
[input.shape[1] > input.shape[2] ? Math.trunc((input.shape[1] - input.shape[2]) / 2) : 0, input.shape[1] > input.shape[2] ? Math.trunc((input.shape[1] - input.shape[2]) / 2) : 0], // width before&after
|
[0, 0], // dont touch batch
|
||||||
[0, 0], // dont touch rbg
|
[input.shape[2] > input.shape[1] ? Math.trunc((input.shape[2] - input.shape[1]) / 2) : 0, input.shape[2] > input.shape[1] ? Math.trunc((input.shape[2] - input.shape[1]) / 2) : 0], // height before&after
|
||||||
];
|
[input.shape[1] > input.shape[2] ? Math.trunc((input.shape[1] - input.shape[2]) / 2) : 0, input.shape[1] > input.shape[2] ? Math.trunc((input.shape[1] - input.shape[2]) / 2) : 0], // width before&after
|
||||||
t.pad = tf.pad(input, padding);
|
[0, 0], // dont touch rbg
|
||||||
t.resize = tf.image.resizeBilinear(t.pad, [inputSize[1][0], inputSize[1][1]]);
|
];
|
||||||
const final = tf.div(t.resize, constants.tf255);
|
t.pad = tf.pad(input, padding);
|
||||||
|
t.resize = tf.image.resizeBilinear(t.pad, [inputSize[1][0], inputSize[1][1]]);
|
||||||
|
final = tf.div(t.resize, constants.tf255);
|
||||||
|
} else if (input.shape[1] !== inputSize[1][0]) { // if input needs resizing
|
||||||
|
t.resize = tf.image.resizeBilinear(input, [inputSize[1][0], inputSize[1][1]]);
|
||||||
|
final = tf.div(t.resize, constants.tf255);
|
||||||
|
} else { // if input is already in a correct resolution just normalize it
|
||||||
|
final = tf.div(input, constants.tf255);
|
||||||
|
}
|
||||||
Object.keys(t).forEach((tensor) => tf.dispose(t[tensor]));
|
Object.keys(t).forEach((tensor) => tf.dispose(t[tensor]));
|
||||||
return final;
|
return final;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,10 +50,12 @@ export function calc(newResult: Result, config: Config): Result {
|
||||||
position: [
|
position: [
|
||||||
bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * bufferedResult.body[i].keypoints[j].position[0] + keypoint.position[0]) / bufferedFactor : keypoint.position[0],
|
bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * bufferedResult.body[i].keypoints[j].position[0] + keypoint.position[0]) / bufferedFactor : keypoint.position[0],
|
||||||
bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * bufferedResult.body[i].keypoints[j].position[1] + keypoint.position[1]) / bufferedFactor : keypoint.position[1],
|
bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * bufferedResult.body[i].keypoints[j].position[1] + keypoint.position[1]) / bufferedFactor : keypoint.position[1],
|
||||||
|
bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (bufferedResult.body[i].keypoints[j].position[2] || 0) + (keypoint.position[2] || 0)) / bufferedFactor : keypoint.position[2],
|
||||||
],
|
],
|
||||||
positionRaw: [
|
positionRaw: [
|
||||||
bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * bufferedResult.body[i].keypoints[j].positionRaw[0] + keypoint.positionRaw[0]) / bufferedFactor : keypoint.position[0],
|
bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * bufferedResult.body[i].keypoints[j].positionRaw[0] + keypoint.positionRaw[0]) / bufferedFactor : keypoint.position[0],
|
||||||
bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * bufferedResult.body[i].keypoints[j].positionRaw[1] + keypoint.positionRaw[1]) / bufferedFactor : keypoint.position[1],
|
bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * bufferedResult.body[i].keypoints[j].positionRaw[1] + keypoint.positionRaw[1]) / bufferedFactor : keypoint.position[1],
|
||||||
|
bufferedResult.body[i].keypoints[j] ? ((bufferedFactor - 1) * (bufferedResult.body[i].keypoints[j].positionRaw[2] || 0) + (keypoint.positionRaw[2] || 0)) / bufferedFactor : keypoint.position[1],
|
||||||
],
|
],
|
||||||
}))) as Array<{ score: number, part: string, position: [number, number, number?], positionRaw: [number, number, number?] }>;
|
}))) as Array<{ score: number, part: string, position: [number, number, number?], positionRaw: [number, number, number?] }>;
|
||||||
const annotations: Record<string, Point[][]> = {};
|
const annotations: Record<string, Point[][]> = {};
|
||||||
|
|
Loading…
Reference in New Issue