https://github.com/sphericalkat/faceverify-lib
https://github.com/sphericalkat/faceverify-lib
Last synced: 9 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/sphericalkat/faceverify-lib
- Owner: SphericalKat
- License: mit
- Created: 2020-05-19T10:41:27.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T11:41:38.000Z (over 2 years ago)
- Last Synced: 2025-04-05T01:21:50.006Z (about 1 year ago)
- Language: Kotlin
- Size: 6.5 MB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Faceverify-lib
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.
## Installation
In your project level `build.gradle` file, add the following:
```gradle
allprojects {
repositories {
google()
jcenter()
maven { url "http://jitpack.io/" } // <-- THIS MUST BE ADDED
}
}
```
In your app level `build.gradle` file, add the following dependency:
```gradle
dependencies {
implementation 'com.github.ATechnoHazard:faceverify-lib:0.1.0'
}
```
And finally, add this to the app-level `build.gradle` to ensure uncompressed models
```gradle
android {
...
aaptOptions {
noCompress "tflite"
}
}
```
## Usage
### Initialize the library
```kotlin
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)
}
```
### Cropping the most prominent face from a bitmap
```kotlin
val croppedBitmap = FaceUtils.cropBitmapWithFace(someBitmap, mtcnn)
```
> **Note**: This might return a null bitmap if no faces were detected. Handle consequent errors appropriately.
### Comparing two bitmaps containing cropped faces
```kotlin
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
}
```