Skip to content

Commit

Permalink
Merge pull request #59 from Yoonit-Labs/feature/face-extra
Browse files Browse the repository at this point in the history
Feature/face extra
  • Loading branch information
Goulartvic authored Apr 15, 2021
2 parents eca5473 + 25bfd6c commit 03857af
Show file tree
Hide file tree
Showing 12 changed files with 325 additions and 278 deletions.
42 changes: 34 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ A Android plugin to provide:
* [Start capturing face images](#start-capturing-face-images)
* [Start scanning QR Codes](#start-capturing-face-images)
* [API](#api)
* [Variables](#variables)
* [Methods](#methods)
* [Events](#events)
* [Face Analysis](#face-analysis)
* [Head Movements](#head-movements)
* [Image Quality](#image-quality)
* [KeyError](#keyerror)
* [Message](#message)
* [To contribute and make it better](#to-contribute-and-make-it-better)
Expand Down Expand Up @@ -147,7 +149,16 @@ fun buildCameraEventListener(): CameraEventListener = object : CameraEventListen
```

## API


### Variables

| Variable | Type | Default Value | Description
| - | - | - | -
| detectionTopSize | Float | '0.0f' | Represents the percentage. Positive value enlarges and negative value reduce the top side of the detection. Use the `setDetectionBox` to have a visual result.
| detectionRightSize | Float | '0.0f' | Represents the percentage. Positive value enlarges and negative value reduce the right side of the detection. Use the `setDetectionBox` to have a visual result.
| detectionBottomSize | Float | '0.0f' | Represents the percentage. Positive value enlarges and negative value reduce the bottom side of the detection. Use the `setDetectionBox` to have a visual result.
| detectionLeftSize | Float | '0.0f' | Represents the percentage. Positive value enlarges and negative value reduce the left side of the detection. Use the `setDetectionBox` to have a visual result.

### Methods

| Function | Parameters | Valid values | Return Type | Description
Expand All @@ -170,7 +181,6 @@ fun buildCameraEventListener(): CameraEventListener = object : CameraEventListen
| setDetectionMaxSize | `maximumSize: Float` | Value between `0` and `1`. Represents the percentage. | void | Set face/qrcode maximum size to detect in percentage related with the camera preview.
| setFaceContours | `enable: Boolean` | `true` or `false`. | void | Set to enable/disable face contours when face detected.
| setFaceContoursColor | `alpha: Int, red: Int, green: Int, blue: Int` | Positive value between 0 and 255. | void | Set face contours ARGB color. Default value is `(100, 255, 255, 255)`.
| setFacePaddingPercent | `facePaddingPercent: Float` | Any positive `Float` value. | void | Set face image and bounding box padding in percent.
| setROI | `enable: Boolean` | `true` or `false`. | void | Enable/disable the region of interest capture.
| setROITopOffset | `topOffset: Float` | Value between `0` and `1`. Represents the percentage. | void | Camera preview top distance in percentage.
| setROIRightOffset | `rightOffset: Float` | Value between `0` and `1`. Represents the percentage. | void | Camera preview right distance in percentage.
Expand Down Expand Up @@ -225,6 +235,22 @@ Here we explaining the above gif and how reached the "results". Each "movement"
| Horizontal | `headEulerAngleY` | Super Left | Left | Frontal | Right | Super Right |
| Tilt | `headEulerAngleZ` | Super Right | Right | Frontal | Left | Super Left |

### Image Quality

The image quality is the classification of the three attributes: darkness, lightness and sharpness. Result available in the `onImageCaptured` event. Let's see each parameter specifications:

| Threshold | Classification
| - | -
| **Darkness** |
| darkness > 0.7 | Too dark
| darkness <= 0.7 | Acceptable
| **Lightness** |
| lightness > 0.65 | Too light
| lightness <= 0.65 | Acceptable
| **Sharpness** |
| sharpness >= 0.1591 | Blurred
| sharpness < 0.1591 | Acceptable

### KeyError

Pre-define key error constants used by the `onError` event.
Expand All @@ -240,7 +266,6 @@ Pre-define key error constants used by the `onError` event.
| INVALID_DETECTION_BOX_COLOR | Tried to input invalid detection box ARGB value color.
| INVALID_MINIMUM_SIZE | Tried to input invalid minimum size.
| INVALID_MAXIMUM_SIZE | Tried to input invalid maximum size.
| INVALID_FACE_PADDING_PERCENT | Tried to input invalid face padding percent.
| INVALID_FACE_CONTOURS_COLOR | Tried to input invalid face contour ARGB value color.
| INVALID_ROI_TOP_OFFSET | Tried to input invalid region of interest top offset.
| INVALID_ROI_RIGHT_OFFSET | Tried to input invalid region of interest right offset.
Expand All @@ -254,11 +279,12 @@ Pre-define key error constants used by the `onError` event.

Pre-define message constants used by the `onMessage` event.

| Message | Description
| - | -
| INVALID_MINIMUM_SIZE | Face/QRCode width percentage in relation of the screen width is less than the set (`setDetectionMinSize`).
| INVALID_MAXIMUM_SIZE | Face/QRCode width percentage in relation of the screen width is more than the set (`setDetectionMaxSize`).
| INVALID_OUT_OF_ROI | Face bounding box is out of the set region of interest (`setROI`).
| Message | Description
| - | -
| INVALID_MINIMUM_SIZE | Face/QRCode width percentage in relation of the screen width is less than the set (`setDetectionMinSize`).
| INVALID_MAXIMUM_SIZE | Face/QRCode width percentage in relation of the screen width is more than the set (`setDetectionMaxSize`).
| INVALID_OUT_OF_ROI | Face bounding box is out of the set region of interest (`setROI`).
| INVALID_TORCH_LENS_USAGE | Torch not available with camera lens "front" (`setTorch`).

## To contribute and make it better

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ 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.setDetectionBox(true)
this.cameraView.startPreview()
this.captureType = "face"

this.cameraView.setComputerVisionLoadModels(arrayListOf(
this.getModelPath("mask_custom_model.pt")
Expand Down Expand Up @@ -380,7 +381,7 @@ class MainActivity : AppCompatActivity() {
"x: $x, y: $y, w: $width, h: $height. \n" +
"leftEye: $leftEyeOpenProbability \n" +
"rightEye: $rightEyeOpenProbability \n" +
"smilling: $smilingProbability \n" +
"smiling: $smilingProbability \n" +
"head X angle: $headEulerAngleX \n" +
"head Y angle: $headEulerAngleY \n" +
"head Z angle: $headEulerAngleZ"
Expand Down
153 changes: 101 additions & 52 deletions yoonit-camera/src/main/java/ai/cyberlabs/yoonit/camera/CameraView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import ai.cyberlabs.yoonit.camera.interfaces.CameraEventListener
import ai.cyberlabs.yoonit.camera.models.CaptureOptions
import android.content.Context
import android.graphics.Color
import android.graphics.RectF
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.FrameLayout
Expand Down Expand Up @@ -256,6 +257,96 @@ open class CameraView @JvmOverloads constructor(
CaptureOptions.detectionBoxColor = Color.argb(alpha, red, green, blue)
}

/**
* Limit the minimum face capture size.
* This variable is the face detection box percentage in relation with the UI graphic view.
* The value must be between 0 and 1.
*
* For example, if set 0.5, will capture face with the detection box width occupying
* at least 50% of the screen width.
*
* @param minimumSize The face capture min size value.
* Default value is 0.0f.
*/
fun setDetectionMinSize(minimumSize: Float) {
if (minimumSize < 0.0f || minimumSize > 1.0f) {
throw IllegalArgumentException(KeyError.INVALID_MINIMUM_SIZE)
}

CaptureOptions.minimumSize = minimumSize
}

/**
* Limit the maximum face capture size.
* This variable is the face detection box percentage in relation with the UI graphic view.
* The value must be between 0 and 1.
*
* For example, if set 0.7, will capture face with the detection box width occupying
* at least 70% of the screen width.
*
* @param maximumSize The face capture max size value.
* Default value is 1.0f.
*/
fun setDetectionMaxSize(maximumSize: Float) {
if (maximumSize < 0.0f || maximumSize > 1.0f) {
throw IllegalArgumentException(KeyError.INVALID_MAXIMUM_SIZE)
}

CaptureOptions.maximumSize = maximumSize
}

/**
* Represents the percentage.
* Positive value enlarges and negative value reduce the top side of the detection.
* Use the `setDetectionBox` to have a visual result.
*
* Default value: `0.0f`
*/
var detectionTopSize: Float = CaptureOptions.detectionTopSize
set(value) {
CaptureOptions.detectionTopSize = value
field = value
}

/**
* Represents the percentage.
* Positive value enlarges and negative value reduce the right side of the detection.
* Use the `setDetectionBox` to have a visual result.
*
* Default value: `0.0f`
*/
var detectionRightSize: Float = CaptureOptions.detectionRightSize
set(value) {
CaptureOptions.detectionRightSize = value
field = value
}

/**
* Represents the percentage.
* Positive value enlarges and negative value reduce the bottom side of the detection.
* Use the `setDetectionBox` to have a visual result.
*
* Default value: `0.0f`
*/
var detectionBottomSize: Float = CaptureOptions.detectionBottomSize
set(value) {
CaptureOptions.detectionBottomSize = value
field = value
}

/**
* Represents the percentage.
* Positive value enlarges and negative value reduce the left side of the detection.
* Use the `setDetectionBox` to have a visual result.
*
* Default value: `0.0f`
*/
var detectionLeftSize: Float = CaptureOptions.detectionLeftSize
set(value) {
CaptureOptions.detectionLeftSize = value
field = value
}

/**
* Set to enable/disable face contours when face detected.
*
Expand All @@ -275,7 +366,12 @@ open class CameraView @JvmOverloads constructor(
* @param blue The blue value.
* Default value is `(100, 255, 255, 255)`.
*/
fun setFaceContoursColor(alpha: Int, red: Int, green: Int, blue: Int) {
fun setFaceContoursColor(
alpha: Int,
red: Int,
green: Int,
blue: Int
) {
if (
alpha < 0 || alpha > 255 ||
red < 0 || red > 255 ||
Expand All @@ -295,59 +391,12 @@ open class CameraView @JvmOverloads constructor(
* Default value is false.
*/
fun setTorch(enable: Boolean) {
this.cameraController.setTorch(enable)
}

/**
* Set saving face images time interval in milli seconds.
*
* @param facePaddingPercent The percent to enlarge the bounding box.
* Default value is 0.0.
*/
fun setFacePaddingPercent(facePaddingPercent: Float) {
if (facePaddingPercent < 0.0f) {
throw IllegalArgumentException(KeyError.INVALID_FACE_PADDING_PERCENT)
}

CaptureOptions.facePaddingPercent = facePaddingPercent
}

/**
* Limit the minimum face capture size.
* This variable is the face detection box percentage in relation with the UI graphic view.
* The value must be between 0 and 1.
*
* For example, if set 0.5, will capture face with the detection box width occupying
* at least 50% of the screen width.
*
* @param minimumSize The face capture min size value.
* Default value is 0.0f.
*/
fun setDetectionMinSize(minimumSize: Float) {
if (minimumSize < 0.0f || minimumSize > 1.0f) {
throw IllegalArgumentException(KeyError.INVALID_MINIMUM_SIZE)
if (CaptureOptions.cameraLens == CameraSelector.LENS_FACING_FRONT) {
this.cameraEventListener?.onMessage(Message.INVALID_TORCH_LENS_USAGE)
return
}

CaptureOptions.minimumSize = minimumSize
}

/**
* Limit the maximum face capture size.
* This variable is the face detection box percentage in relation with the UI graphic view.
* The value must be between 0 and 1.
*
* For example, if set 0.7, will capture face with the detection box width occupying
* at least 70% of the screen width.
*
* @param maximumSize The face capture max size value.
* Default value is 1.0f.
*/
fun setDetectionMaxSize(maximumSize: Float) {
if (maximumSize < 0.0f || maximumSize > 1.0f) {
throw IllegalArgumentException(KeyError.INVALID_MAXIMUM_SIZE)
}

CaptureOptions.maximumSize = maximumSize
this.cameraController.setTorch(enable)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ object KeyError {
// Tried to input invalid maximum size.
const val INVALID_MAXIMUM_SIZE = "INVALID_MAXIMUM_SIZE"

// Tried to input invalid face padding percent.
const val INVALID_FACE_PADDING_PERCENT = "INVALID_FACE_PADDING_PERCENT"

// Tried to input invalid face contour ARGB value color.
const val INVALID_FACE_CONTOURS_COLOR = "INVALID_FACE_CONTOURS_COLOR"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ object Message {

// Face bounding box is out of the setted region of interest.
const val INVALID_OUT_OF_ROI = "INVALID_OUT_OF_ROI"

// Not available with camera lens "front".
const val INVALID_TORCH_LENS_USAGE = "INVALID_TORCH_LENS_USAGE"
}
Loading

0 comments on commit 03857af

Please sign in to comment.