Firebase Face Detection
Introduction
What is firebase Face detection?
With ML Kit’s face detection API, you can detect faces in an image, identify key facial features, and get the contours of detected faces.
With face detection, you can get the information you need to perform tasks like embellishing selfies and portraits or generating avatars from a user’s photo. Because ML Kit can perform face detection in real-time, you can use it in applications like video chat or games that respond to the player’s expressions.
Face detection is the process of automatically locating human faces in visual media (digital images or videos). A face that is detected is reported at a position with an associated size and orientation. Once a face is detected, it can be searched for landmarks such as the eyes and nose.
Other than Face Detection below features are also available in ML kit.
- Text Recognition
- Object detection and tracking
- Image labelling
- AutoML Vision Edge
- Barcode scanning
- Landmark recognition
- Language ID
- On-device translation
- Smart Reply
When talking about face recognition in firebase we must know some key features. Let’s talk about the key factors so you can easily get an idea what the hell is this.
- Face tracking
- Landmark
- Contour
- Classification
Face tracking
Face tracking can be done in both images and video. In the videos, it is happening in real-time. From the Firebase SDK, it can track multiple faces at once. For tracking firebase using angle called Euler. Such as Euler X, Euler Y, and Euler Z. ML Kit always reports the Euler Z angle of a detected face. The Euler Y angle is available only when using the “accurate” mode setting of the face detector (as opposed to the “fast” mode setting, which takes some shortcuts to make detection faster). The Euler X angle is not supported.
Landmark
In the ML kit face is categorizes to different landmarks such as mouth, nose, left eye, right eye, etc. This is because it is easy to supply data under the landmark. ML kit first recognizes the whole face. Landmark detection is an optional feature that you need to enable if you wish to use it. The following table will show you all the landmarks which can be identified on your face and their respective Euler angle.
Contour
Contour is a set of points which represent the shape of the facial features. In the ML kit for each facial feature, there are a set of contour points. Below you can see how much contour points are used to each facial feature.
Classification
ML kit identifies the features of the face and analyses the status of the face. Currently ML kit support 2 classification such as smiling and eyes open.
So, in this tutorial, we will be going to analyses facial features by capturing an image from the camera or open an image from the library. So, no more go into details. Let’s get started to implement a sample app with android.
Implementation
For firebase face detection we are going to use FirebaseVisionFaceDetector FirebaseVisionImage libraries.
Step 1
First, you need to create a new project in the Firebase console. Create an empty Android project. Then go to the Firebase console. From the console Add and give the project name as shown below and press continue.
Then you will be redirected to the dashboard of the Firebase. On the dashboard select an android icon to configure Firebase with your project.
You must add the Android Package name for this. You can easily find the package name from the project you created from the android studio. Open your created project. Then open the Android Manifest file. Then you can find your package name. copy and paste the name to the Firebase. There are other two entries that are optional to register the app in Firebase. If you wish you can add them.
The next step is downloading the configured JSON file.
After you downloaded this file from the Firebase you must add it to the android project app folder as shown in this figure.
Then, you must add some dependencies to your gradle files. You can easily follow them on firebase guidelines.
Step 2
In this app, we are going to access the files of the mobile phone. So, we need to get permission to access the file. So, go to the AndroidManifest.xml file and add the following permission.
Step 3
Now we are going to design the layout to display the selected image and results after the face recognition is completed. In the activity_main.xml add the following layout
Step 4
Now we are going to create a separate java file for handle images that we are going to open through the app. I’m going to name this as BaseApplication.java
Step 5
Finally, we are going to implement the MainActivity.java class.
Conclusion
In this tutorial, we learn what are the features of Firebase ML kit face detection. And then we learn how to use them with a sample application. From this, you can get an idea of how to develop creative mobile apps by using Firebase ML kit face detection. If you face any trouble please follow the source code in the GitHub.