Kairos is the easist way add Face-Recognition to your web applications. Our API provides a full-featured and robust Face-Recognition backend, right out of the box. This is the Javascript wrapper for the Kairos Facial Recognition API. The package includes a client (kairos.js) you can use as an easy client to the API. Continue reading to learn how to integrate Kairos into your web application.
Thanks to contributions by some of our customers, we also have Ruby and .NET wrappers available. Also see our PHP SDK and iOS SDK.
- jQuery.
- A web browser.
- Basic knowledge of Javascript and HTML5.
If you just want to do a quick test run, open one of the example scripts included with the SDK and follow these steps:
- Create your free developer account
- Log into the Kairos Developer Dashboard
- Create an application and copy your App Id & App Key
- Paste them into the constructor method in example.html
- Open the script in your browser.
- Drag an image into the drop zone and wait for the response.
- Create your free Kairos developer account if you don't already have one.
- Log into the dashboard and create a new app.
- Copy your App ID & App Key (you'll need them later).
- Download the SDK and unzip the package.
- Open the folder named Kairos-SDK-Javascript and locate the kairos.js file.
- Place the client file (kairos.js) somewhere within your project.
- Include kairos.js where needed in your project.
<script src="assets/js/kairos.js"></script>
Before you can make API calls you'll need to pass Kairos your credentials App Id and App Key (You only need to do this once). Paste your App Id and App Key into the constructor method like so:
// instantiates a new instance of the Kairos client
var kairos = new Kairos("app_id", "api_key");
The Enroll method registers a face for later recognitions. Here's an example of enrolling a face (subject) using a method that accepts image data in base64 format, and enrolls it as a new subject into your specified gallery:
// (1) set up your callback method
function myDetectCallback(response)
{
alert(response.responseText);
}
// (2) prepare your parameters
var base64_data = 'iVBORw0KGgoAAA ... ABJRU5ErkJggg==\r\n';
var subject_id = 'eric';
var gallery_id = 'friends1';
// (3) pass your params and callback to the function
kairos.enroll(image_data, gallery_id, subject_id, myCallback);
The Recognize method takes an image of a subject and attempts to match it against a given gallery of previously-enrolled subjects. Here's an example of recognizing a subject using a method that accepts image data in base64 format, sends it to the API, and returns a match and confidence value:
// (1) set up your callback method
function myDetectCallback(response)
{
alert(response.responseText);
}
// (2) prepare your parameters
base64_data = 'iVBORw0KGgoAAA ... ABJRU5ErkJggg==\r\n';
gallery_id = 'friends1';
// (3) ... as well as any optional parameters you wish to send
var options = { "threshold" : 0.75 };
// (4) pass your params and callback to the function
kairos.recognize(image_data, gallery_id, myCallback, options);
The Detect method takes an image of a subject and returns various attributes pertaining to the face features. The detect methods also accept an optional 'selector' parameter, allowing you to tweak the scope of the response (see docs for more info on the detect selector). Here's an example of using detect via method that accepts image data in base64 format, sends it to the API, and returns face attributes:
// (1) set up your callback method
function myDetectCallback(response)
{
alert(response.responseText);
}
// (2) prepare your parameters
base64_data = 'iVBORw0KGgoAAA ... ABJRU5ErkJggg==\r\n';
// (3) ... as well as any optional parameters you wish to send
var options = { "selector" : "FULL" };
// (4) pass your params and callback to the function
kairos.detect(image_data, myCallback, options);
This method returns a list of all galleries you've created:
// (1) set up your callback method
function myDetectCallback(response)
{
alert(response.responseText);
}
// (2) pass your callback to the function
kairos.viewGalleries(myCallback);
This method returns a list of all subjects for a given gallery:
// (1) set up your callback method
function myDetectCallback(response)
{
alert(response.responseText);
}
// (2) prepare your parameters
var gallery_id = 'friends1';
// (3) pass your params and callback to the function
kairos.viewSubjectsInGallery(gallery_id, myCallback);
This method removes a subject from given gallery:
// (1) set up your callback method
function myDetectCallback(response)
{
alert(response.responseText);
}
// (2) prepare your parameters
var subject_id = 'sam';
var gallery_id = 'friends1';
// (3) pass your params and callback to the function
kairos.removeSubjectFromGallery(subject_id, gallery_id, myCallback);
Many of the Kairos API methods expose optional parameters for customizing the api response to fit your use-case. Here is an example of sending custom options in the detect call to limit the response to attributes pertaining to the eyes:
//...
var options = { "threshold" : 0.75, "minHeadScale" : 0.5, "selector" : "FACE" };
kairos.recognize(image_data, gallery_id, myCallback, options);
##Support Have an issue? Contact us or create an issue on GitHub