mirror of https://github.com/vladmandic/human
add body 3d interpolation
parent
9fd7ea723e
commit
67667160cb
|
@ -64,6 +64,8 @@ function calculateBoxes(keypoints: Array<BodyKeypoint>, outputSize: [number, num
|
|||
async function prepareImage(input: Tensor): Promise<Tensor> {
|
||||
const t: Record<string, Tensor> = {};
|
||||
if (!input.shape || !input.shape[1] || !input.shape[2]) return input;
|
||||
let final: Tensor;
|
||||
if (input.shape[1] !== input.shape[2]) { // only pad if width different than height
|
||||
padding = [
|
||||
[0, 0], // dont touch batch
|
||||
[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
|
||||
|
@ -72,7 +74,13 @@ async function prepareImage(input: Tensor): Promise<Tensor> {
|
|||
];
|
||||
t.pad = tf.pad(input, padding);
|
||||
t.resize = tf.image.resizeBilinear(t.pad, [inputSize[1][0], inputSize[1][1]]);
|
||||
const final = tf.div(t.resize, constants.tf255);
|
||||
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]));
|
||||
return final;
|
||||
}
|
||||
|
|
|
@ -50,10 +50,12 @@ export function calc(newResult: Result, config: Config): Result {
|
|||
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[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: [
|
||||
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[2] || 0) + (keypoint.positionRaw[2] || 0)) / bufferedFactor : keypoint.position[1],
|
||||
],
|
||||
}))) as Array<{ score: number, part: string, position: [number, number, number?], positionRaw: [number, number, number?] }>;
|
||||
const annotations: Record<string, Point[][]> = {};
|
||||
|
|
Loading…
Reference in New Issue