This project aims to provide a simple API for cropping faces from a bitmap and comparing two faces to verify that they're from the same person.
In your project level build.gradle
file, add the following:
allprojects {
repositories {
google()
jcenter()
maven { url "http://jitpack.io/" } // <-- THIS MUST BE ADDED
}
}
In your app level build.gradle
file, add the following dependency:
dependencies {
implementation 'com.github.ATechnoHazard:faceverify-lib:0.1.0'
}
And finally, add this to the app-level build.gradle
to ensure uncompressed models
android {
...
aaptOptions {
noCompress "tflite"
}
}
lateinit var mtcnn: MTCNN
lateinit var mfn: MobileFaceNet
try {
mtcnn = MTCNN(assets)
mfn = MobileFaceNet(assets)
} catch (e: IOException) {
Log.e("TAG", "Error initing models", e)
}
val croppedBitmap = FaceUtils.cropBitmapWithFace(someBitmap, mtcnn)
Note: This might return a null bitmap if no faces were detected. Handle consequent errors appropriately.
val similarity = mfn.compare(bitmap1, bitmap2)
if (similarity > MobileFaceNet.THRESHOLD) { // 0.8 by default, customize if you want
// faces match
} else {
// faces don't match
}