From 0df1d12007453f5787af4d81e3860e71c7182a33 Mon Sep 17 00:00:00 2001 From: HaroldoTeruya Date: Wed, 31 Mar 2021 17:57:42 -0300 Subject: [PATCH] feat: improve demo to display face analysis data --- .../yoonit/camerademo/MainActivity.kt | 73 +++++- app/src/main/res/layout/activity_main.xml | 213 ++++++++++++++++-- app/src/main/res/values/strings.xml | 2 + 3 files changed, 266 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/ai/cyberlabs/yoonit/camerademo/MainActivity.kt b/app/src/main/java/ai/cyberlabs/yoonit/camerademo/MainActivity.kt index 26a75f5..da34dd0 100644 --- a/app/src/main/java/ai/cyberlabs/yoonit/camerademo/MainActivity.kt +++ b/app/src/main/java/ai/cyberlabs/yoonit/camerademo/MainActivity.kt @@ -76,6 +76,9 @@ class MainActivity : AppCompatActivity() { this.cameraView.setROIRightOffset(0.1f) this.cameraView.setROITopOffset(0.1f) this.cameraView.setROIBottomOffset(0.1f) + this.captureType = "face" + this.cameraView.setSaveImageCaptured(true) + this.cameraView.setComputerVision(true) this.cameraView.startPreview() this.cameraView.setComputerVisionLoadModels(arrayListOf( @@ -114,11 +117,22 @@ class MainActivity : AppCompatActivity() { } } - fun onConfigurationSwitchClick(view: View) { - if (view is SwitchCompat) { - this.features_panel.visibility = - if (view.isChecked) View.VISIBLE - else View.INVISIBLE + fun onConfigurationRadioButtonClicked(view: View) { + if (view is RadioButton) { + when (view.getId()) { + R.id.configuration_radio_button -> { + this.configurations.visibility = View.VISIBLE + this.analysis.visibility = View.GONE + } + R.id.analysis_radio_button -> { + this.configurations.visibility = View.GONE + this.analysis.visibility = View.VISIBLE + } + R.id.hide_radio_button -> { + this.configurations.visibility = View.GONE + this.analysis.visibility = View.GONE + } + } } } @@ -325,6 +339,13 @@ class MainActivity : AppCompatActivity() { } Log.d(TAG, "${it.first}: $results") } + + if (inferences.isNotEmpty() && inferences.first().second.isNotEmpty()) { + val probability = inferences.first().second.first() + maskTextView.text = if (probability < 0.3) "Masked" else "Not Masked" + maskProbabilityTextView.text = probability.toString() + } + Log.d(TAG, " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .") info_textview.text = "$count/$total" @@ -348,12 +369,52 @@ class MainActivity : AppCompatActivity() { "onFaceDetected: \n" + "x: $x, y: $y, w: $width, h: $height. \n" + "leftEye: $leftEyeOpenProbability \n" + - "rightEye: $leftEyeOpenProbability \n" + + "rightEye: $rightEyeOpenProbability \n" + "smilling: $smilingProbability \n" + "head X angle: $headEulerAngleX \n" + "head Y angle: $headEulerAngleY \n" + "head Z angle: $headEulerAngleZ" ) + + leftEyeTextView.text = if (leftEyeOpenProbability != null) { + leftEyeProbabilityTextView.text = leftEyeOpenProbability.toString() + if (leftEyeOpenProbability > 0.8) "Open" else "Close" + } else "-" + rightEyeTextView.text = if (rightEyeOpenProbability != null) { + rightEyeProbabilityTextView.text = rightEyeOpenProbability.toString() + if (rightEyeOpenProbability > 0.8) "Open" else "Close" + } else "-" + smlingTextView.text = if (smilingProbability != null) { + smilingProbabilityTextView.text = smilingProbability.toString() + if (smilingProbability > 0.8) "Smiling" else "Not Smiling" + } else "-" + + headVerticalAngleTextView.text = headEulerAngleX.toString() + headVerticalTextView.text = + if (headEulerAngleX < -36) "Super Down" + else if (-36 < headEulerAngleX && headEulerAngleX < -12) "Down" + else if (-12 < headEulerAngleX && headEulerAngleX < 12) "Frontal" + else if (12 < headEulerAngleX && headEulerAngleX < 36) "Up" + else if (36 < headEulerAngleX) "Super Up" + else "-" + + headHorizontalAngleTextView.text = headEulerAngleY.toString() + headHorizontalTextView.text = + if (headEulerAngleY < -36) "Super Right" + else if (-36 < headEulerAngleY && headEulerAngleY < -12) "Right" + else if (-12 < headEulerAngleY && headEulerAngleY < 12) "Frontal" + else if (12 < headEulerAngleY && headEulerAngleY < 36) "Left" + else if (36 < headEulerAngleY) "Super Left" + else "-" + + headTiltAngleTextView.text = headEulerAngleZ.toString() + headTiltTextView.text = + if (headEulerAngleZ < -36) "Super Left" + else if (-36 < headEulerAngleZ && headEulerAngleZ < -12) "Left" + else if (-12 < headEulerAngleZ && headEulerAngleZ < 12) "Frontal" + else if (12 < headEulerAngleZ && headEulerAngleZ < 36) "Right" + else if (36 < headEulerAngleZ) "Super Right" + else "-" } override fun onFaceUndetected() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index c9a7752..ee1e31b 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -67,17 +67,41 @@ android:orientation="vertical" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"> - - + android:orientation="horizontal"> + + + + - @@ -238,18 +261,15 @@ android:onClick="onCameraLensRadioButtonClicked" android:text="@string/camera_back" /> - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 558a19a..f399053 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -26,4 +26,6 @@ ROI Color Min Size 70% Max Size 90% + Analysis + Hide \ No newline at end of file