Skip to content

Instantly share code, notes, and snippets.

@JulienHe
Created December 9, 2019 06:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JulienHe/9a5686d0d2dd66540038accf258867d0 to your computer and use it in GitHub Desktop.
Save JulienHe/9a5686d0d2dd66540038accf258867d0 to your computer and use it in GitHub Desktop.
Spark AR - Mouth Corner
/**
* Author: Julien Henrotte @julien_he
* Company: UltraSuperNew http://ultrasupernew.com/
*/
/**
* Modules
*/
const Scene = require('Scene');
const FaceTracking = require('FaceTracking');
const Patches = require('Patches');
const root = Scene.root; // Just a shorthand
const face = FaceTracking.face(0); // Track the first face that appear on the screen
/**
* Points position of the mouth.
* Init now to use it later on
*/
const mouthPoint = {
leftX: face.mouth.leftCorner.x,
leftY: face.mouth.leftCorner.y,
righttX: face.mouth.rightCorner.x,
rightY: face.mouth.rightCorner.y,
topX: face.mouth.upperLipCenter.x,
topY: face.mouth.upperLipCenter.y,
bottomX: face.mouth.lowerLipCenter.x,
bottomY: face.mouth.lowerLipCenter.y
};
/**
* Subscribe to the mouth open event
*/
FaceTracking.face(0)
.mouth.openness.monitor()
.subscribe(function(event) {
if (event.newValue > 0.4) {
// When the mouth is open, we update the position of each corner and send it back to Spark AR.
Patches.setScalarValue('mouthleftXCorner', mouthPoint.leftX);
Patches.setScalarValue('mouthleftYCorner', mouthPoint.leftY);
Patches.setScalarValue('mouthRightXCorner', mouthPoint.righttX);
Patches.setScalarValue('mouthRightYCorner', mouthPoint.rightY);
Patches.setScalarValue('topLipsCenterX', mouthPoint.topX);
Patches.setScalarValue('topLipsCenterY', mouthPoint.topY);
Patches.setScalarValue('bottomLipsCenterX', mouthPoint.bottomX);
Patches.setScalarValue('bottomLipsCenterY', mouthPoint.bottomY);
}
});
@a7madgamal
Copy link

thanks!

@a7madgamal
Copy link

a7madgamal commented Apr 20, 2020

I just wanted the center so I simplified it to this:

const FaceTracking = require('FaceTracking');
const Patches = require('Patches');

Patches.setPointValue('mouthCenter', FaceTracking.face(0).mouth.center);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment