-
Notifications
You must be signed in to change notification settings - Fork 13
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
Geometry for FaceLandmark vs Camera #1
Comments
Hi @JpEncausse. Thanks for your feedback. Beside the parallax effect, the code is mainly adapted from the first chapter of https://discoverthreejs.com/book/ The parallax effect is implemented through only two files: In geometry.js, things are a bit messy because various options are available (cf. the README file). You can only focus on the parts corresponding to The essential steps are the following:
predictions = await model.estimateFaces({
input: ctx.getImageData(0, 0, width, height),
predictIrises: (distanceMethod == 1),
flipHorizontal: false
});
keypoints = predictions[0].scaledMesh;
centerX = keypoints[168][0];
centerY = keypoints[168][1];
return [Math.atan(2 * (centerX - width / 2) / width * Math.tan(HFOV / 2)),
Math.atan(2 * (centerY - height / 2) / height * Math.tan(VFOV / 2)),
d
]
const result = await getLocation(context, width, height);
...
const [angle1, angle2, distance] = result;
...
let d = this.distance;
const tan1 = -Math.tan(this.angle1);
const tan2 = -Math.tan(this.angle2);
const z = Math.sqrt(d * d / (1 + tan1 * tan1 + tan2 * tan2))
const cameraPosition = [z * tan1, z * tan2, z];
const fov = 180 / Math.PI * 2 * Math.atan(HALF_DIAGONAL / d);
return [cameraPosition, fov]; In Loop.js, we just periodically update the parameters for the camera: const result = await this.faceTracker.getCameraParameters();
if (result !== null) {
const [cameraPosition, fov] = result;
this.cameraPosition = cameraPosition;
this.fov = fov;
this.lastUpdate = Date.now();
} I hope this helps! |
Hello,
I love the parralax effect but I'm a little lost in your code.
I implemented this codepen describe from this topic but I don't think it's a good idea to move the cube. It's better to move the camera according to the FaceLandmark like you did.
But ... I'ml lost ... how to move the camera according to FaceMesh ?
The text was updated successfully, but these errors were encountered: