How to Build A Facial Recognition Mobile App with React Native, Expo, and Kairos

A short introduction and example of building a face-detecting mobile application.

Mohammad Kashif Sulaiman
Crowdbotics
5 min readJan 3, 2019

--

Facial recognition — once the stuff of sci-fi novels — is now a widely used technology. In this post, I will I will show you how to develop a basic face-detecting mobile app with React Native and Expo.

React Native is a fast and easy tool to develop cross-platform mobile apps.
Expo makes React Native development even faster by providing a whole host of out-of-the-box features to get your app up and running quickly.

Lets get started!

Building with React Native? Scaffold and deploy React Native apps with quality-assured templates for free in the Crowdbotics app builder. Check it out.

First, you have to install Expo CLI (preferably as global) in your system. To do this, run the following command in the command prompt at the location where you want to save your project.

( You’ll need to have Node.js (version 6 or newer) installed on your computer to run this command. Download the latest version of Node.js.)

Now run this next command to start your project. Name it whatever you would like.

Start coding in your working file. By default it is App.js .

Import the things you want to use in your project.

First, get permission from the use their camera when the app starts.

Now, if the user gives permission to use the camera, use the camera component where you want to open the camera.

If a face is detected, the ‘handleFacesDetected’ function will be triggered.

I am adding ‘ref’ attribute and a button to the camera component so that when we press the button it will send our image to the recognization process to evaluate whether to enroll or to recognize it.

We are able to detect faces on camera.Our next objective is to recognize the faces.

To achieve this goal we will use Kairos. To use Kairos, you have to visit https://kairos.com and sign up as a developer.

Once you sign up, you will get your App Key and App ID. These are the two things that would make sure that you are able to access the server at Kairos in order to be able to process your images. It is the key to your face being recognized.

Next, configure your app with these credentials

You can use different APIs by using base URL like this:
(POST) https://api.kairos.com/enroll
(POST) https://api.kairos.com/recognize
(POST) https://api.kairos.com/detect
(POST) https://api.kairos.com/gallery/list_all
etc.

Create your functions by using these APIs.

Examples of the enrolling and recognizing functions are as follows:

Where,

  • image => Publicly accessible URL, file upload or Base64 encoded photo.
  • subject_id => (can be a random) key for your image (defined by you) is used as an identifier for the face.
  • gallery_name => is the folder name where your photos will be saved (defined by you) is used to identify the gallery.

A successful response of ‘recognize’ API should be like this:

And, here you go! In ‘images,’ you have candidate lists that include the matching face ids.

This is a brief introduction to face recognition. You can also check Kairos docs for more details.

Thanks for reading! :-)

If you make a cool facial recognition app with React Native, Kairos, or Expo, drop a link in the comments. I’d love to check it out.

Building A Web Or Mobile App?

Crowdbotics is the fastest way to build, launch and scale an application.

Developer? Try out the Crowdbotics App Builder to quickly scaffold and deploy apps with a variety of popular frameworks.

Busy or non-technical? Join hundreds of happy teams building software with Crowdbotics PMs and expert developers. Scope timeline and cost with Crowdbotics Managed App Development for free.

--

--