How to Implement Eye-Enlarging and Face-Shaping Functions Using HUAWEI ML Kit's Face Detection Capability
We take a look at a quick tutorial on how to integrate a machine learning (ML) kit into a camera-based application that can detect faces and facial patterns.
Join the DZone community and get the full member experience.Join For Free
Sometimes, we can't help taking photos to capture unforgettable moments in life. But most of us are not professional photographers or models, so our photographs can end up falling short of our expectations. So, how can we create more impressive photos? If you have an image processing app on your phone, it can automatically detect faces in a photo and you can adjust the image until you're happy with it. So, after looking around online, I found HUAWEI ML Kit's face detection capability. By integrating this capability, you can add beautification functions to your apps. Have a try!
ML Kit's face detection capability detects up to 855 facial keypoints and returns the coordinates for the face's contour, eyebrows, eyes, nose, mouth, and ears, as well as the angle of the face. Once you've integrated this capability, you can quickly create beauty apps and enable users to add fun facial effects and features to their images.
Face detection also detects whether the subject's eyes are open, whether they're wearing glasses or a hat, whether they have a beard, and even their gender and age. This is useful if you want to add a parental control function to your app which prevents children from getting too close to their phone or staring at the screen for too long.
In addition, face detection can detect up to seven facial expressions, including smiling, neutral, angry, disgusted, frightened, sad, and surprised faces. This is great if you want to create apps such as smile-cameras.
You can integrate any of these capabilities as needed. At the same time, face detection supports image and video stream detection, cross-frame face tracking, and multi-face detection. It really is powerful! Now, let's see how to integrate this capability.
Face Detection Development
You can find detailed information about the preparations you need to make on the HUAWEI Developers-Development Process. Here, we'll just look at the most important procedures.
1.1 Configure the Maven Repository Address in the Project-Level build.gradle File
1.2 Add Configurations to the File Header
After integrating the SDK, add the following configuration to the file header:
1.3 Configure SDK Dependencies in the App-Level build.gradle File
1.4 Add These Statements to the AndroidManifest.xml File so the Machine Learning Model Can Update Automatically
1.5 Apply for Camera Permission
2. Code Development
2.1 Create a Face Analyzer by Using the Default Parameter Configurations
2.2 Create an MLFrame Object by Using the android.graphics.Bitmap file for the Analyzer to Detect Images
2.3 Call the asyncAnalyseFrame Method to Perform Face Detection
2.4 Use the Progress Bar to Process the Face in the Image
smallFaceMesh methods to implement the eye-enlarging algorithm and face-shaping algorithm.
2.5 Release the Analyzer After the Detection is Complete
Now, let's see what it can do. Pretty cool, right?
For more information, please visit HUAWEI Developers.
For detailed instructions, please visit Development Guide.
You can join the HMS Core developer discussion on Reddit.
You can download the demo and sample code from GitHub.
To solve integration problems, please go to Stack Overflow.
Opinions expressed by DZone contributors are their own.