Last active
September 7, 2016 18:28
-
-
Save 4F2E4A2E/6619cb3ed732eee48e040c56f5769732 to your computer and use it in GitHub Desktop.
Faceapi Meteor.wrapAsync
This file contains 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
/** | |
* Created by 4F2E4A2E & Daniel P. on 27.08.2016. | |
*/ | |
var oxford = require('project-oxford'), | |
fs = require('fs'); | |
/** | |
* TODO: Require the faceapi's id in order to start the app &/ give the possibility to add one via the ui. | |
* @type {oxford.Client} | |
*/ | |
var client = new oxford.Client(''); | |
/** | |
* TODO: Require the person's group id in order to start the app &/ give the possibility to add one via the ui. | |
* @type {oxford.Person.Group} | |
*/ | |
var personGroupId = ''; | |
/** | |
* TODO: Pass the error response, correctly. | |
* Detects faces on an image, returning random face ids and coordinates of the location of the detected faces. | |
* Mind the Gap: The face ids are unique but differs from each detect call to the faceapi. Yep. | |
* @param imageData Base64 encode image data. Big thanks to cthrash, https://github.com/felixrieseberg/project-oxford/issues/15#issuecomment-244839202 | |
* @param callback | |
*/ | |
var detectAsync = function (imageData, callback) { | |
client.face.detect({ | |
path: getImageData(imageData), | |
returnFaceId: true, | |
analyzesAge: false, | |
analyzesGender: false | |
}).then(function (response) { | |
callback && callback(null, response); | |
}).catch(function (error) { | |
callback(null, error); | |
return; | |
}); | |
}, detectSync = Meteor.wrapAsync(detectAsync); | |
Meteor.methods({ | |
checkFaceMatch: function (imageData) { | |
console.log('Checking for a face match.'); | |
var detectedFacesList = detectSync(imageData); | |
console.log('detectedFacesList: ' + JSON.stringify(detectedFacesList)); | |
if (detectedFacesList.errno) { | |
return 'Server side error number: ' + detectedFacesList.errno + ' and code: ' + detectedFacesList.code; | |
} else if (detectedFacesList.code) { | |
return detectedFacesList; | |
} | |
return person; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment