Skip to content

Commit

Permalink
Merge pull request #56 from Yoonit-Labs/improvedemo
Browse files Browse the repository at this point in the history
feat: improve demo to display face analysis data
  • Loading branch information
TeruyaHaroldo authored Mar 31, 2021
2 parents 60fc5ee + 0df1d12 commit 37f85cd
Show file tree
Hide file tree
Showing 3 changed files with 266 additions and 22 deletions.
73 changes: 67 additions & 6 deletions app/src/main/java/ai/cyberlabs/yoonit/camerademo/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
}
}
}
}

Expand Down Expand Up @@ -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"
Expand All @@ -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() {
Expand Down
213 changes: 197 additions & 16 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,48 @@
android:orientation="vertical"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<androidx.appcompat.widget.SwitchCompat
android:layout_width="wrap_content"
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="true"
android:onClick="onConfigurationSwitchClick"
android:background="@android:color/darker_gray"
android:padding="16dp"
android:text="@string/configuration" />
android:orientation="horizontal">
<RadioButton
android:id="@+id/configuration_radio_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="false"
android:onClick="onConfigurationRadioButtonClicked"
android:text="@string/configuration" />
<RadioButton
android:id="@+id/analysis_radio_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="true"
android:onClick="onConfigurationRadioButtonClicked"
android:text="@string/face_analysis" />
<RadioButton
android:id="@+id/hide_radio_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="false"
android:onClick="onConfigurationRadioButtonClicked"
android:text="@string/hide" />
</RadioGroup>

<LinearLayout
android:id="@+id/features_panel"
android:id="@+id/configurations"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alpha="0.8"
android:background="@android:color/darker_gray"
android:orientation="vertical"
android:padding="16dp"
app:layout_constraintTop_toTopOf="parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand All @@ -110,7 +133,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:checked="false"
android:checked="true"
android:onClick="onImageCaptureSwitchClick"
android:text="@string/image_capture" />
<androidx.appcompat.widget.SwitchCompat
Expand Down Expand Up @@ -150,7 +173,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:checked="false"
android:checked="true"
android:onClick="onComputerSwitchSwitchClick"
android:text="@string/computer_vision" />
</LinearLayout>
Expand Down Expand Up @@ -238,18 +261,15 @@
android:onClick="onCameraLensRadioButtonClicked"
android:text="@string/camera_back" />
</RadioGroup>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/color_encoding" />

<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:orientation="horizontal">

<RadioButton
android:id="@+id/rgb_radio_button"
android:layout_width="wrap_content"
Expand All @@ -258,7 +278,6 @@
android:checked="true"
android:onClick="onColorEncodingRadioButtonClicked"
android:text="@string/rgb_encoding" />

<RadioButton
android:id="@+id/yuv_radio_button"
android:layout_width="wrap_content"
Expand All @@ -267,12 +286,10 @@
android:onClick="onColorEncodingRadioButtonClicked"
android:text="@string/yuv_encoding" />
</RadioGroup>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/capture_types" />

<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down Expand Up @@ -313,5 +330,169 @@
android:text="@string/capture_type_frame" />
</RadioGroup>
</LinearLayout>

<LinearLayout
android:id="@+id/analysis"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alpha="0.8"
android:background="@android:color/darker_gray"
android:orientation="vertical"
android:padding="16dp"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10px"
android:text="Left Eye Open:" />
<TextView
android:id="@+id/leftEyeTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="-" />
<TextView
android:id="@+id/leftEyeProbabilityTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10px"
android:text="Right Eye Open:" />
<TextView
android:id="@+id/rightEyeTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="-" />
<TextView
android:id="@+id/rightEyeProbabilityTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10px"
android:text="Smiling:" />
<TextView
android:id="@+id/smlingTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="-" />
<TextView
android:id="@+id/smilingProbabilityTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10px"
android:text="Vertical:" />
<TextView
android:id="@+id/headVerticalTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="-" />
<TextView
android:id="@+id/headVerticalAngleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10px"
android:text="Horizontal:" />
<TextView
android:id="@+id/headHorizontalTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="-" />
<TextView
android:id="@+id/headHorizontalAngleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10px"
android:text="Tilt:" />
<TextView
android:id="@+id/headTiltTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="-" />
<TextView
android:id="@+id/headTiltAngleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10px"
android:text="Using Mask:" />
<TextView
android:id="@+id/maskTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="-" />
<TextView
android:id="@+id/maskProbabilityTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@
<string name="roi_color">ROI Color</string>
<string name="detection_min">Min Size 70%</string>
<string name="detection_max">Max Size 90%</string>
<string name="face_analysis">Analysis</string>
<string name="hide">Hide</string>
</resources>

0 comments on commit 37f85cd

Please sign in to comment.