Last active
December 19, 2015 13:32
-
-
Save cecilemuller/beff6ef6e3f77807fa30 to your computer and use it in GitHub Desktop.
RealSense face tracking in ES6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
/* global intel */ | |
const DeviceOrientation = intel.realsense.DeviceOrientation; | |
const StreamType = intel.realsense.StreamType; | |
const SenseManager = intel.realsense.SenseManager; | |
let sense; | |
let faceModule; | |
let faceConfig; | |
let imageSize; | |
function stop(error){ | |
if (error instanceof Error){ | |
console.error(error); | |
} | |
if (typeof sense !== 'undefined'){ | |
sense.release().then(() => { | |
sense = undefined; | |
}); | |
} | |
} | |
function set_faces(sender, data){ | |
console.log('[faces]', data); | |
// | |
// Make use of the 3D Face data here | |
// | |
} | |
function start(){ | |
SenseManager.createInstance() | |
.then(result => { | |
sense = result; | |
return intel.realsense.face.FaceModule.activate(result); | |
}) | |
.then(result => { | |
faceModule = result; | |
return faceModule.createActiveConfiguration(); | |
}) | |
.then(result => { | |
faceConfig = result; | |
faceConfig.detection.isEnabled = true; | |
faceConfig.detection.maxTrackedFaces = 1; | |
faceConfig.trackingMode = 1; // 3D | |
return faceConfig.applyChanges(); | |
}) | |
.then(() => { | |
faceModule.onFrameProcessed = set_faces; | |
return sense.init(); | |
}) | |
.then(() => { | |
if (sense.captureManager.device.deviceInfo.orientation === DeviceOrientation.DEVICE_ORIENTATION_FRONT_FACING){ | |
// F200 | |
faceConfig.landmarks.isEnabled = true; | |
faceConfig.landmarks.maxTrackedFaces = 1; | |
faceConfig.pose.isEnabled = true; | |
faceConfig.expressions.properties.isEnabled = true; | |
} else { | |
// R200 | |
faceConfig.landmarks.isEnabled = false; | |
faceConfig.pose.isEnabled = false; | |
faceConfig.expressions.properties.isEnabled = false; | |
} | |
return faceConfig.applyChanges(); | |
}) | |
.then(() => { | |
imageSize = sense.captureManager.queryImageSize(StreamType.STREAM_TYPE_COLOR); | |
return sense.streamFrames(); | |
}) | |
.then(() => { | |
console.log('Now streaming ' + imageSize.width + 'x' + imageSize.height); | |
}) | |
.catch(stop); | |
} | |
function initialize(status){ | |
switch (status.nextStep){ | |
case 'ready': | |
start(); | |
break; | |
// case 'runtime': | |
// case 'driver': | |
// case 'unsupported': | |
default: | |
console.error('Fails to initialize.'); | |
break; | |
} | |
} | |
document.addEventListener('DOMContentLoaded', () => { | |
SenseManager.detectPlatform(['face3d'], []).then(initialize).catch(stop); | |
}); | |
window.addEventListener('beforeunload', stop); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Example</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1, minimal-ui"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> | |
</head> | |
<body> | |
<!-- Autobahn (http://autobahn.ws/js), required by realsense.js --> | |
<script src="thirdparty/autobahn.min.js"></script> | |
<!-- RealSense SDK (https://software.intel.com/en-us/intel-realsense-sdk/download) --> | |
<script src="thirdparty/realsense.js"></script> | |
<script src="application.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment