-
Notifications
You must be signed in to change notification settings - Fork 2
Add SimQ quality assessment library to SimFace #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0c0a1f1
Add a separate quality assessment library
Thinkorswim f199f8c
Bump SimFace version number
Thinkorswim d62ca1f
Fix robolectric name
Thinkorswim 8b0ad95
Fix minSdk mismatch
Thinkorswim 61c58c7
Update FaceDetectionProcessorTest.kt
Thinkorswim efa7429
Update initialization, tests, helper functioons
Thinkorswim 9a91db0
Make objects internal
Thinkorswim 23aae84
Add ImageAnalyzer OpenCV abstraction
Thinkorswim 1919a39
Refactor paramaters handling
Thinkorswim 6567b59
Update low quality image
Thinkorswim 71ade3b
Address copilot complaints
Thinkorswim 1f183ed
Add ktlint formatting
Thinkorswim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 hidden or 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,52 @@ | ||
| plugins { | ||
| alias(libs.plugins.android.library) | ||
| alias(libs.plugins.jetbrains.kotlin.android) | ||
| } | ||
|
|
||
| android { | ||
| namespace = "com.simprints.simq" | ||
| compileSdk = 36 | ||
|
|
||
| defaultConfig { | ||
| minSdk = 23 | ||
|
|
||
| testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
| consumerProguardFiles("consumer-rules.pro") | ||
| } | ||
|
|
||
| buildTypes { | ||
| release { | ||
| isMinifyEnabled = false | ||
| proguardFiles( | ||
| getDefaultProguardFile("proguard-android-optimize.txt"), | ||
| "proguard-rules.pro", | ||
| ) | ||
| } | ||
| } | ||
| compileOptions { | ||
| sourceCompatibility = JavaVersion.VERSION_17 | ||
| targetCompatibility = JavaVersion.VERSION_17 | ||
| } | ||
| kotlinOptions { | ||
| jvmTarget = "17" | ||
| } | ||
|
|
||
| testOptions { | ||
| unitTests { | ||
| isIncludeAndroidResources = true | ||
| } | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
|
|
||
| implementation(libs.androidx.core.ktx) | ||
| implementation(libs.androidx.appcompat) | ||
| implementation(libs.material) | ||
| api(libs.opencv) | ||
|
|
||
| androidTestImplementation(libs.truth) | ||
| androidTestImplementation(libs.androidx.junit) | ||
| androidTestImplementation(libs.androidx.espresso.core) | ||
| androidTestImplementation(libs.kotlinx.coroutines.test) | ||
| } |
Empty file.
This file contains hidden or 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 |
111 changes: 111 additions & 0 deletions
111
simq/src/androidTest/java/com/simprints/simq/AlignmentAnalysisTest.kt
This file contains hidden or 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,111 @@ | ||
| package com.simprints.simq | ||
|
|
||
| import com.google.common.truth.Truth.assertThat | ||
| import com.simprints.simq.analysis.AlignmentAnalysis | ||
| import org.junit.Test | ||
|
|
||
| class AlignmentAnalysisTest { | ||
| private val maxAngle = 20.0 | ||
| private val maxIndividualAngle = 25.0 | ||
|
|
||
| @Test | ||
| fun perfectAlignmentReturnsScoreOf1() { | ||
| val score = | ||
| AlignmentAnalysis.calculateScore( | ||
| pitch = 0.0, | ||
| yaw = 0.0, | ||
| roll = 0.0, | ||
| maxAngle = maxAngle, | ||
| maxIndividualAngle = maxIndividualAngle, | ||
| ) | ||
| assertThat(score).isWithin(0.001).of(1.0) | ||
| } | ||
|
|
||
| @Test | ||
| fun angleAtHalfMaxThresholdReturnsScoreOf0_5() { | ||
| val halfAngle = maxAngle / 2 | ||
| val score = | ||
| AlignmentAnalysis.calculateScore( | ||
| pitch = halfAngle, | ||
| yaw = halfAngle, | ||
| roll = halfAngle, | ||
| maxAngle = maxAngle, | ||
| maxIndividualAngle = maxIndividualAngle, | ||
| ) | ||
| assertThat(score).isWithin(0.001).of(0.5) | ||
| } | ||
|
|
||
| @Test | ||
| fun negativeAnglesAreTreatedAsAbsoluteValues() { | ||
| val score1 = | ||
| AlignmentAnalysis.calculateScore( | ||
| pitch = -10.0, | ||
| yaw = -10.0, | ||
| roll = -10.0, | ||
| maxAngle = maxAngle, | ||
| maxIndividualAngle = maxIndividualAngle, | ||
| ) | ||
|
|
||
| val score2 = | ||
| AlignmentAnalysis.calculateScore( | ||
| pitch = 10.0, | ||
| yaw = 10.0, | ||
| roll = 10.0, | ||
| maxAngle = maxAngle, | ||
| maxIndividualAngle = maxIndividualAngle, | ||
| ) | ||
|
|
||
| assertThat(score1).isWithin(0.001).of(score2) | ||
| } | ||
|
|
||
| @Test | ||
| fun anySingleAngleExceedingMaxIndividualAngleRejectsEntireScore() { | ||
| // Test pitch rejection | ||
| val pitchScore = | ||
| AlignmentAnalysis.calculateScore( | ||
| pitch = 26.0, | ||
| yaw = 0.0, | ||
| roll = 0.0, | ||
| maxAngle = maxAngle, | ||
| maxIndividualAngle = maxIndividualAngle, | ||
| ) | ||
| assertThat(pitchScore).isWithin(0.001).of(0.0) | ||
|
|
||
| // Test yaw rejection | ||
| val yawScore = | ||
| AlignmentAnalysis.calculateScore( | ||
| pitch = 0.0, | ||
| yaw = 26.0, | ||
| roll = 0.0, | ||
| maxAngle = maxAngle, | ||
| maxIndividualAngle = maxIndividualAngle, | ||
| ) | ||
| assertThat(yawScore).isWithin(0.001).of(0.0) | ||
|
|
||
| // Test roll rejection | ||
| val rollScore = | ||
| AlignmentAnalysis.calculateScore( | ||
| pitch = 0.0, | ||
| yaw = 0.0, | ||
| roll = 26.0, | ||
| maxAngle = maxAngle, | ||
| maxIndividualAngle = maxIndividualAngle, | ||
| ) | ||
| assertThat(rollScore).isWithin(0.001).of(0.0) | ||
| } | ||
|
|
||
| @Test | ||
| fun mixedAnglesCalculateAverageScoreCorrectly() { | ||
| // Perfect pitch, half-max yaw, max roll | ||
| val score = | ||
| AlignmentAnalysis.calculateScore( | ||
| pitch = 0.0, // Score: 1.0 | ||
| yaw = 10.0, // Score: 0.5 (10/20) | ||
| roll = 20.0, // Score: 0.0 (20/20) | ||
| maxAngle = maxAngle, | ||
| maxIndividualAngle = maxIndividualAngle, | ||
| ) | ||
| // Average: (1.0 + 0.5 + 0.0) / 3 = 0.5 | ||
| assertThat(score).isWithin(0.001).of(0.5) | ||
| } | ||
| } |
90 changes: 90 additions & 0 deletions
90
simq/src/androidTest/java/com/simprints/simq/BitmapExtTest.kt
This file contains hidden or 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,90 @@ | ||
| package com.simprints.simq | ||
|
|
||
| import android.graphics.Bitmap | ||
| import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
| import com.google.common.truth.Truth.assertThat | ||
| import com.simprints.simq.utils.centerCrop | ||
| import com.simprints.simq.utils.resizeToArea | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
|
|
||
| @RunWith(AndroidJUnit4::class) | ||
| class BitmapExtTest { | ||
| @Test | ||
| fun centerCropBitmapWithNoDisplacementCropsCenter() { | ||
| val bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888) | ||
| val cropped = | ||
| bitmap.centerCrop( | ||
| centerCrop = 0.5f, | ||
| horizontalDisplacement = 0.0f, | ||
| verticalDisplacement = 0.0f, | ||
| ) | ||
|
|
||
| assertThat(cropped.width).isEqualTo(50) | ||
| assertThat(cropped.height).isEqualTo(50) | ||
| } | ||
|
|
||
| @Test | ||
| fun centerCropBitmapWithFullCropReturnsSameSize() { | ||
| val bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888) | ||
| val cropped = | ||
| bitmap.centerCrop( | ||
| centerCrop = 1.0f, | ||
| horizontalDisplacement = 0.0f, | ||
| verticalDisplacement = 0.0f, | ||
| ) | ||
|
|
||
| assertThat(cropped.width).isEqualTo(100) | ||
| assertThat(cropped.height).isEqualTo(100) | ||
| } | ||
|
|
||
| @Test | ||
| fun resizeBitmapMaintainsAspectRatioForSquareBitmap() { | ||
| val bitmap = Bitmap.createBitmap(512, 512, Bitmap.Config.ARGB_8888) | ||
| val resized = bitmap.resizeToArea(targetArea = 65536.0) | ||
|
|
||
| assertThat(resized.width).isEqualTo(256) | ||
| assertThat(resized.height).isEqualTo(256) | ||
| } | ||
|
|
||
| @Test | ||
| fun resizeBitmapMaintainsAspectRatioForRectangularBitmap() { | ||
| val bitmap = Bitmap.createBitmap(800, 400, Bitmap.Config.ARGB_8888) | ||
| val resized = bitmap.resizeToArea(targetArea = 65536.0) | ||
|
|
||
| val aspectRatio = resized.width.toDouble() / resized.height.toDouble() | ||
| assertThat(aspectRatio).isWithin(0.01).of(2.0) | ||
|
|
||
| val area = resized.width * resized.height | ||
| assertThat(area.toDouble()).isWithin(1000.0).of(65536.0) | ||
| } | ||
|
|
||
| @Test | ||
| fun resizeBitmapScalesDownLargeBitmap() { | ||
| val bitmap = Bitmap.createBitmap(1024, 1024, Bitmap.Config.ARGB_8888) | ||
| val resized = bitmap.resizeToArea(targetArea = 65536.0) | ||
|
|
||
| assertThat(resized.width).isLessThan(bitmap.width) | ||
| assertThat(resized.height).isLessThan(bitmap.height) | ||
| } | ||
|
|
||
| @Test | ||
| fun resizeBitmapScalesUpSmallBitmap() { | ||
| val bitmap = Bitmap.createBitmap(64, 64, Bitmap.Config.ARGB_8888) | ||
| val resized = bitmap.resizeToArea(targetArea = 65536.0) | ||
|
|
||
| assertThat(resized.width).isGreaterThan(bitmap.width) | ||
| assertThat(resized.height).isGreaterThan(bitmap.height) | ||
| } | ||
|
|
||
| @Test | ||
| fun resizeBitmapHandlesDifferentTargetAreas() { | ||
| val bitmap = Bitmap.createBitmap(512, 512, Bitmap.Config.ARGB_8888) | ||
|
|
||
| val smallResize = bitmap.resizeToArea(targetArea = 16384.0) | ||
| val largeResize = bitmap.resizeToArea(targetArea = 262144.0) | ||
|
|
||
| assertThat(smallResize.width).isLessThan(largeResize.width) | ||
| assertThat(smallResize.height).isLessThan(largeResize.height) | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions
44
simq/src/androidTest/java/com/simprints/simq/QualityWeightsTest.kt
This file contains hidden or 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,44 @@ | ||
| package com.simprints.simq | ||
|
|
||
| import android.graphics.Bitmap | ||
| import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
| import com.google.common.truth.Truth.assertThat | ||
| import org.junit.Before | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
|
|
||
| @RunWith(AndroidJUnit4::class) | ||
| class QualityWeightsTest { | ||
| private fun createTestBitmap( | ||
| width: Int = 256, | ||
| height: Int = 256, | ||
| ): Bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888) | ||
|
|
||
| @Test | ||
| fun calculateFaceQualityWithAllWeightsMaximizingOneMetric() { | ||
| val bitmap = createTestBitmap() | ||
|
|
||
| // Only alignment weight | ||
| val alignmentOnlySimQ = | ||
| SimQ( | ||
| faceWeights = | ||
| QualityWeights( | ||
| alignment = 1.0, | ||
| blur = 0.0, | ||
| brightness = 0.0, | ||
| contrast = 0.0, | ||
| eyeOpenness = 0.0, | ||
| ), | ||
| ) | ||
|
|
||
| val alignmentOnly = | ||
| alignmentOnlySimQ.calculateFaceQuality( | ||
| bitmap = bitmap, | ||
| pitch = 0.0, | ||
| yaw = 0.0, | ||
| roll = 0.0, | ||
| ) | ||
|
|
||
| assertThat(alignmentOnly).isEqualTo(1f) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a suspicion that this removes the "simface" from the project; both should be included.
I would suggest moving all of the simFace-related stuff into a subfolder first, tho.