-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is the initial version of face recognition & liveness detect & f…
…ace capture & face attribute
- Loading branch information
1 parent
136128e
commit db2f113
Showing
75 changed files
with
4,256 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
local.properties | ||
/.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
plugins { | ||
id 'com.android.application' | ||
id 'org.jetbrains.kotlin.android' | ||
} | ||
|
||
android { | ||
namespace 'com.kbyai.faceattribute' | ||
compileSdk 33 | ||
|
||
defaultConfig { | ||
applicationId "com.kbyai.faceattribute" | ||
minSdk 24 | ||
targetSdk 33 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
|
||
ndk { | ||
abiFilters 'arm64-v8a', 'armeabi-v7a' | ||
} | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = '1.8' | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation 'androidx.core:core-ktx:1.7.0' | ||
implementation 'androidx.appcompat:appcompat:1.6.1' | ||
implementation 'com.google.android.material:material:1.8.0' | ||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4' | ||
implementation 'androidx.preference:preference:1.2.0' | ||
implementation 'androidx.preference:preference-ktx:1.2.0' | ||
|
||
implementation "androidx.camera:camera-core:1.0.0-beta12" | ||
implementation "androidx.camera:camera-camera2:1.0.0-beta12" | ||
implementation "androidx.camera:camera-lifecycle:1.0.0-beta12" | ||
implementation 'androidx.camera:camera-view:1.0.0-alpha19' | ||
|
||
implementation project(path: ':libfacesdk') | ||
|
||
testImplementation 'junit:junit:4.13.2' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.5' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
24 changes: 24 additions & 0 deletions
24
app/src/androidTest/java/com/kbyai/faceattribute/ExampleInstrumentedTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.kbyai.faceattribute | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("com.kbyai.faceattribute", appContext.packageName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
|
||
<uses-permission android:name="android.permission.CAMERA" /> | ||
|
||
<uses-feature android:name="android.hardware.camera" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:dataExtractionRules="@xml/data_extraction_rules" | ||
android:fullBackupContent="@xml/backup_rules" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.FaceAttribute" | ||
tools:targetApi="31"> | ||
<activity | ||
android:name=".AttributeActivity" | ||
android:exported="false" /> | ||
<activity | ||
android:name=".ResultActivity" | ||
android:exported="false" | ||
android:screenOrientation="portrait" /> | ||
<activity | ||
android:name=".SettingsActivity" | ||
android:exported="false" | ||
android:label="@string/title_activity_settings" | ||
android:screenOrientation="portrait" /> | ||
<activity | ||
android:name=".AboutActivity" | ||
android:exported="false" | ||
android:screenOrientation="portrait" /> | ||
<activity | ||
android:name=".CameraActivity" | ||
android:exported="false" | ||
android:screenOrientation="portrait" /> | ||
<activity | ||
android:name=".CaptureActivity" | ||
android:exported="false" | ||
android:screenOrientation="portrait" /> | ||
<activity | ||
android:name=".MainActivity" | ||
android:exported="true" | ||
android:screenOrientation="portrait"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
87 changes: 87 additions & 0 deletions
87
app/src/main/java/com/kbyai/faceattribute/AboutActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package com.kbyai.faceattribute | ||
|
||
import android.content.Intent | ||
import android.content.pm.ResolveInfo | ||
import android.net.Uri | ||
import android.os.Bundle | ||
import android.widget.TextView | ||
import androidx.appcompat.app.AppCompatActivity | ||
|
||
|
||
class AboutActivity : AppCompatActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_about) | ||
|
||
findViewById<TextView>(R.id.txtMail).setOnClickListener { | ||
val intent = Intent(Intent.ACTION_SEND) | ||
intent.type = "plain/text" | ||
intent.putExtra(Intent.EXTRA_EMAIL, arrayOf("[email protected]")) | ||
intent.putExtra(Intent.EXTRA_SUBJECT, "License Request") | ||
intent.putExtra(Intent.EXTRA_TEXT, "") | ||
startActivity(Intent.createChooser(intent, "")) | ||
} | ||
|
||
findViewById<TextView>(R.id.txtWhatsapp).setOnClickListener { | ||
val general = Intent(Intent.ACTION_VIEW, Uri.parse("https://com.whatsapp/kbyai")) | ||
val generalResolvers: HashSet<String> = HashSet() | ||
val generalResolveInfo: List<ResolveInfo> = packageManager.queryIntentActivities(general, 0) | ||
for (info in generalResolveInfo) { | ||
if (info.activityInfo.packageName != null) { | ||
generalResolvers.add(info.activityInfo.packageName) | ||
} | ||
} | ||
|
||
val telegram = Intent(Intent.ACTION_VIEW, Uri.parse("https://wa.me/19092802609")) | ||
var goodResolver = 0 | ||
|
||
val resInfo: List<ResolveInfo> = packageManager.queryIntentActivities(telegram, 0) | ||
if (!resInfo.isEmpty()) { | ||
for (info in resInfo) { | ||
if (info.activityInfo.packageName != null && !generalResolvers.contains(info.activityInfo.packageName)) { | ||
goodResolver++ | ||
telegram.setPackage(info.activityInfo.packageName) | ||
} | ||
} | ||
} | ||
|
||
if (goodResolver != 1) { | ||
telegram.setPackage(null) | ||
} | ||
if (telegram.resolveActivity(packageManager) != null) { | ||
startActivity(telegram) | ||
} | ||
} | ||
|
||
findViewById<TextView>(R.id.txtTelegram).setOnClickListener { | ||
val general = Intent(Intent.ACTION_VIEW, Uri.parse("https://t.com/kbyai")) | ||
val generalResolvers: HashSet<String> = HashSet() | ||
val generalResolveInfo: List<ResolveInfo> = packageManager.queryIntentActivities(general, 0) | ||
for (info in generalResolveInfo) { | ||
if (info.activityInfo.packageName != null) { | ||
generalResolvers.add(info.activityInfo.packageName) | ||
} | ||
} | ||
|
||
val telegram = Intent(Intent.ACTION_VIEW, Uri.parse("https://t.me/kbyai")) | ||
var goodResolver = 0 | ||
|
||
val resInfo: List<ResolveInfo> = packageManager.queryIntentActivities(telegram, 0) | ||
if (!resInfo.isEmpty()) { | ||
for (info in resInfo) { | ||
if (info.activityInfo.packageName != null && !generalResolvers.contains(info.activityInfo.packageName)) { | ||
goodResolver++ | ||
telegram.setPackage(info.activityInfo.packageName) | ||
} | ||
} | ||
} | ||
|
||
if (goodResolver != 1) { | ||
telegram.setPackage(null) | ||
} | ||
if (telegram.resolveActivity(packageManager) != null) { | ||
startActivity(telegram) | ||
} | ||
} | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
app/src/main/java/com/kbyai/faceattribute/AttributeActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.kbyai.faceattribute | ||
|
||
import android.graphics.Bitmap | ||
import android.os.Bundle | ||
import android.widget.ImageView | ||
import android.widget.TextView | ||
import androidx.appcompat.app.AppCompatActivity | ||
|
||
class AttributeActivity : AppCompatActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_attribute) | ||
|
||
val faceImage = intent.getParcelableExtra("face_image") as? Bitmap | ||
val livenessScore = intent.getFloatExtra("liveness", 0f) | ||
val yaw = intent.getFloatExtra("yaw", 0f) | ||
val roll = intent.getFloatExtra("roll", 0f) | ||
val pitch = intent.getFloatExtra("pitch", 0f) | ||
val face_quality = intent.getFloatExtra("face_quality", 0f) | ||
val face_luminance = intent.getFloatExtra("face_luminance", 0f) | ||
val left_eye_closed = intent.getFloatExtra("left_eye_closed", 0f) | ||
val right_eye_closed = intent.getFloatExtra("right_eye_closed", 0f) | ||
val face_occlusion = intent.getFloatExtra("face_occlusion", 0f) | ||
val mouth_opened = intent.getFloatExtra("mouth_opened", 0f) | ||
val age = intent.getIntExtra("age", 0) | ||
val gender = intent.getIntExtra("gender", 0) | ||
|
||
findViewById<ImageView>(R.id.imageFace).setImageBitmap(faceImage) | ||
|
||
if (livenessScore > SettingsActivity.getLivenessThreshold(this)) { | ||
val msg = String.format("Liveness: Real, score = %.03f", livenessScore) | ||
findViewById<TextView>(R.id.txtLiveness).text = msg | ||
} else { | ||
val msg = String.format("Liveness: Spoof, score = %.03f", livenessScore) | ||
findViewById<TextView>(R.id.txtLiveness).text = msg | ||
} | ||
|
||
if (face_quality < 0.5f) { | ||
val msg = String.format("Quality: Low, score = %.03f", face_quality) | ||
findViewById<TextView>(R.id.txtQuality).text = msg | ||
} else if(face_quality < 0.75f){ | ||
val msg = String.format("Quality: Medium, score = %.03f", face_quality) | ||
findViewById<TextView>(R.id.txtQuality).text = msg | ||
} else { | ||
val msg = String.format("Quality: High, score = %.03f", face_quality) | ||
findViewById<TextView>(R.id.txtQuality).text = msg | ||
} | ||
|
||
var msg = String.format("Luminance: %.03f", face_luminance) | ||
findViewById<TextView>(R.id.txtLuminance).text = msg | ||
|
||
msg = String.format("Angles: yaw = %.03f, roll = %.03f, pitch = %.03f", yaw, roll, pitch) | ||
findViewById<TextView>(R.id.txtAngles).text = msg | ||
|
||
if (face_occlusion > SettingsActivity.getOcclusionThreshold(this)) { | ||
msg = String.format("Face occluded: score = %.03f", face_occlusion) | ||
findViewById<TextView>(R.id.txtOcclusion).text = msg | ||
} else { | ||
msg = String.format("Face not occluded: score = %.03f", face_occlusion) | ||
findViewById<TextView>(R.id.txtOcclusion).text = msg | ||
} | ||
|
||
msg = String.format("Left eye closed: %b, %.03f, Right eye closed: %b, %.03f", left_eye_closed > SettingsActivity.getEyecloseThreshold(this), | ||
left_eye_closed, right_eye_closed > SettingsActivity.getEyecloseThreshold(this), right_eye_closed) | ||
findViewById<TextView>(R.id.txtEyeClosed).text = msg | ||
|
||
msg = String.format("Mouth opened: %b, %.03f", mouth_opened > SettingsActivity.getMouthopenThreshold(this), mouth_opened) | ||
findViewById<TextView>(R.id.txtMouthOpened).text = msg | ||
|
||
msg = String.format("Age: %d", age) | ||
findViewById<TextView>(R.id.txtAge).text = msg | ||
|
||
if(gender == 0) { | ||
msg = String.format("Gender: Male") | ||
} else { | ||
msg = String.format("Gender: Female") | ||
} | ||
findViewById<TextView>(R.id.txtGender).text = msg | ||
} | ||
} |
Oops, something went wrong.