Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improves extrapolation #49

Merged
merged 4 commits into from
Apr 19, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions public/js/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ function drawFrame(canvas, video, combinedFeatures) {
}

const faceMeshes = combinedFeatures[0];
const handPoses = combinedFeatures[1];
const ctx = canvas.getContext('2d');

ctx.drawImage(
Expand All @@ -67,14 +66,19 @@ function drawFrame(canvas, video, combinedFeatures) {
}

// Render HandPose
let handPoints;
if (handPoses !== undefined && handPoses.length > 0) {
handPoints = handPoses[0].landmarks;
const handAnnotations = handPoses[0].annotations;
drawPoints(ctx, handPoints, 3);
Object.entries(handAnnotations).forEach(([, points]) =>
drawPath(ctx, points)
);
let handPoints = null;
if (combinedFeatures[1] !== null) {
const handPoses = combinedFeatures[1];

// TODO Remove/merge this to the upper branch to avoid unnecessary complexity and computation
if (handPoses !== undefined && handPoses.length > 0) {
Berkmann18 marked this conversation as resolved.
Show resolved Hide resolved
handPoints = handPoses[0].landmarks;
const handAnnotations = handPoses[0].annotations;
drawPoints(ctx, handPoints, 3);
Object.entries(handAnnotations).forEach(([, points]) =>
drawPath(ctx, points)
);
}
}

return [facePoints, handPoints];
Expand Down
9 changes: 7 additions & 2 deletions public/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,12 @@ function processKeyPoints(combinedKeyPoints) {
}

if (state.isInferenceOn) {
if (facePoints !== undefined && handPoints !== undefined) {
// TODO Look into merging/removing this condition to the line above to avoid unnecessary computations
if (facePoints !== undefined && handPoints !== null) {
Berkmann18 marked this conversation as resolved.
Show resolved Hide resolved
computeInference(facePoints, handPoints).then((inference) =>
updateInferenceText(inference[0])
);
}
} else updateInferenceText(0);
} else if (!state.isInDevMode) {
document.getElementById('inference-txt').innerHTML = '- %';
}
Expand All @@ -141,6 +142,10 @@ function processKeyPoints(combinedKeyPoints) {
async function startEngine(canvas, video) {
(function update() {
computeCombinedKeyPoints(video)
.then((combinedFeatures) => {
const noHandFound = !combinedFeatures[1].length;
return noHandFound ? [combinedFeatures[0], null] : combinedFeatures;
Berkmann18 marked this conversation as resolved.
Show resolved Hide resolved
})
.then((combinedFeatures) => drawFrame(canvas, video, combinedFeatures))
.then((combinedKeyPoints) => processKeyPoints(combinedKeyPoints))
.then(() => requestAnimationFrame(update))
Expand Down