This project is a sample Android Application to show the power of HMS MLKit Face recognition feature integrated with Android CameraX
In the AndroidManifest.xml is enabled the dependency of the face model for HMS ML Kit with
<meta-data
android:name="com.huawei.hms.ml.DEPENDENCY"
android:value="face" />
In the FaceDetectorProcessor.kt there is the creation of the Face Analyzer responsible to detect the faces in an image
detector = MLAnalyzerFactory.getInstance().getFaceAnalyzer(options)
The option passed as argument can have multiple statements
val faceDetectorOptions = MLFaceAnalyzerSetting.Factory()
.setFeatureType(MLFaceAnalyzerSetting.TYPE_FEATURE_OPENCLOSEEYE)
.setFeatureType(MLFaceAnalyzerSetting.TYPE_FEATURE_EMOTION)
.setFeatureType(MLFaceAnalyzerSetting.TYPE_KEYPOINTS)
.setShapeType(MLFaceAnalyzerSetting.TYPE_SHAPES)
.allowTracing(MLFaceAnalyzerSetting.MODE_TRACING_FAST)
.create()
feel free to check the documentation for more options
Every time the detector detects one or more faces these will be returned in the onSuccess
override fun onSuccess(faces: List<MLFace>, graphicOverlay: GraphicOverlay) {
for (face in faces) {
graphicOverlay.add(FaceGraphic(graphicOverlay, face))
logExtrasForTesting(face)
}
}
From a MLFace object You will be able to get
Also check FaceGraphic.kt for a sample to check how to display the info you want on the canvas
In the OnSwipeTouchListener.kt there is the code to handle the Top to Bottom swype down gesture to change the camera
Open the project with Android Studio 4.0 and run it or alternatively use gradle directly
Enable the permissions asked by the system
Point the camera to a face
Swype down from top to bottom on the screen to change camera
You are encouraged to try it out and study and hack every parts to achieve your own target