Skip to content

Commit

Permalink
Merge pull request #4 from Yoonit-Labs/refactor/remove-parameters-ava…
Browse files Browse the repository at this point in the history
…ilability

Refactor/remove parameters availability
  • Loading branch information
TeruyaHaroldo authored Mar 17, 2021
2 parents ab79aa8 + b776f1f commit 2e18b2b
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.2;
PRODUCT_BUNDLE_IDENTIFIER = ai.cyberlabs.YoonitFacefyDemo;
MARKETING_VERSION = 1.0.4;
PRODUCT_BUNDLE_IDENTIFIER = com.yoonit.facefydemo;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down Expand Up @@ -434,8 +434,8 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.2;
PRODUCT_BUNDLE_IDENTIFIER = ai.cyberlabs.YoonitFacefyDemo;
MARKETING_VERSION = 1.0.4;
PRODUCT_BUNDLE_IDENTIFIER = com.yoonit.facefydemo;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,43 +54,27 @@ class FacefyViewController:
self.facefy?.detect(image!) {
faceDetected in

if let faceDetected: FaceDetected = faceDetected {

print(
"onFaceDetected" +
"\n x: \(faceDetected.boundingBox.minX), y: \(faceDetected.boundingBox.minY), width: \(faceDetected.boundingBox.width), height: \(faceDetected.boundingBox.height)" +
"\n leftEyeOpenProbability: \(faceDetected.hasLeftEyeOpenProbability) \(faceDetected.leftEyeOpenProbability)" +
"\n rightEyeOpenProbability: \(faceDetected.hasRightEyeOpenProbability) \(faceDetected.rightEyeOpenProbability)" +
"\n smilingProbability: \(faceDetected.hasSmilingProbability) \(faceDetected.smilingProbability)" +
"\n headEulerAngleX: \(faceDetected.hasHeadEulerAngleX) \(faceDetected.headEulerAngleX)" +
"\n headEulerAngleY: \(faceDetected.hasHeadEulerAngleY) \(faceDetected.headEulerAngleY)" +
"\n headEulerAngleZ: \(faceDetected.hasHeadEulerAngleZ) \(faceDetected.headEulerAngleZ)"
)

if let faceDetected: FaceDetected = faceDetected {
self.handleDisplayProbability(
label: self.leftEyeLabel,
hasValue: faceDetected.hasLeftEyeOpenProbability,
value: faceDetected.leftEyeOpenProbability,
validText: "Open",
invalidText: "Close"
)
self.handleDisplayProbability(
label: self.rightEyeLabel,
hasValue: faceDetected.hasRightEyeOpenProbability,
value: faceDetected.rightEyeOpenProbability,
validText: "Open",
invalidText: "Close"
)
self.handleDisplayProbability(
label: self.smilingLabel,
hasValue: faceDetected.hasSmilingProbability,
value: faceDetected.smilingProbability,
validText: "Smiling",
invalidText: "Not Smiling"
)

if faceDetected.hasHeadEulerAngleX {
let headEulerAngleX = faceDetected.headEulerAngleX
if let headEulerAngleX = faceDetected.headEulerAngleX {
var headPosition = ""
if headEulerAngleX < -36 {
headPosition = "Super Down"
Expand All @@ -106,8 +90,7 @@ class FacefyViewController:
self.verticalMovementLabel.text = headPosition
}

if faceDetected.hasHeadEulerAngleY {
let headEulerAngleY = faceDetected.headEulerAngleY
if let headEulerAngleY = faceDetected.headEulerAngleY {
var headPosition = ""
if headEulerAngleY < -36 {
headPosition = "Super Right"
Expand All @@ -123,8 +106,7 @@ class FacefyViewController:
self.horizontalMovementLabel.text = headPosition
}

if faceDetected.hasHeadEulerAngleZ {
let headEulerAngleZ = faceDetected.headEulerAngleZ
if let headEulerAngleZ = faceDetected.headEulerAngleZ {
var headPosition = ""
if headEulerAngleZ < -36 {
headPosition = "Super Left"
Expand All @@ -140,7 +122,14 @@ class FacefyViewController:
self.tiltMovementLabel.text = headPosition
}

if let cgImage = image?.cgImage {
if let cgImage = image?.cgImage {

self.graphicView.handleDraw(
image: cgImage,
faceBoundingBox: faceDetected.boundingBox,
faceContours: faceDetected.contours
)

// Crop the face image.
self.faceImageView.image = UIImage(
cgImage: cgImage.cropping(to: faceDetected.boundingBox)!
Expand All @@ -160,12 +149,11 @@ class FacefyViewController:

func handleDisplayProbability(
label: UILabel,
hasValue: Bool,
value: Float,
value: Float?,
validText: String,
invalidText: String
) {
if hasValue {
if let value: Float = value {
label.text = value > 0.8 ? validText : invalidText
}
}
Expand Down
File renamed without changes.
46 changes: 20 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ A iOS plugin to provide:
* Face expressions
* Face movement

<img src="https://raw.githubusercontent.com/Yoonit-Labs/ios-yoonit-facefy/development/facefy.gif" width="300">
<img src="https://raw.githubusercontent.com/Yoonit-Labs/ios-yoonit-facefy/development/facefy.gif" width="300" />

## Table of Contents

Expand Down Expand Up @@ -53,29 +53,29 @@ let facefy: Facefy = Facefy()
self.facefy.detect(image!) { faceDetected in
if let faceDetected: FaceDetected = faceDetected {

if faceDetected.hasLeftEyeOpenProbability {
print(String(format: "%.2f", faceDetected.leftEyeOpenProbability))
if let leftEyeOpenProbability = faceDetected.leftEyeOpenProbability {
print(String(format: "%.2f", leftEyeOpenProbability))
}
if faceDetected.rightEyeOpenProbability {
print(String(format: "%.2f", faceDetected.rightEyeOpenProbability))
if let rightEyeOpenProbability = faceDetected.rightEyeOpenProbability {
print(String(format: "%.2f", rightEyeOpenProbability))
}
if faceDetected.smilingProbability {
if let smilingProbability = faceDetected.smilingProbability {
print(String(format: "%.2f", faceDetected.smilingProbability))
}
if faceDetected.hasHeadEulerAngleX {
print(String(format: "%.2f", faceDetected.headEulerAngleX))
if let hasHeadEulerAngleX = faceDetected.hasHeadEulerAngleX {
print(String(format: "%.2f", hasHeadEulerAngleX))
}
if faceDetected.hasHeadEulerAngleY {
print(String(format: "%.2f", faceDetected.headEulerAngleY))
if let hasHeadEulerAngleY = faceDetected.hasHeadEulerAngleY {
print(String(format: "%.2f", hasHeadEulerAngleY))
}
if faceDetected.hasHeadEulerAngleZ {
print(String(format: "%.2f", faceDetected.headEulerAngleZ))
if let hasHeadEulerAngleZ = faceDetected.hasHeadEulerAngleZ {
print(String(format: "%.2f", hasHeadEulerAngleZ))
}

if let cgImage = image?.cgImage {

// Crop the face image from.
UIImage(
// Crop the face image from the camera frame.
let faceImage = UIImage(
cgImage: cgImage.cropping(to: faceDetected.boundingBox)!
).withHorizontallyFlippedOrientation()
}
Expand All @@ -98,18 +98,12 @@ self.facefy.detect(image!) { faceDetected in
| Attribute | Type | Description |
| - | - | - |
| boundingBox | `CGRect` | The face bounding box related to the image input. |
| leftEyeOpenProbability | `Float` | The left eye open probability. |
| hasLeftEyeOpenProbability | `Bool` | Indicates whether a left eye open probability is available. |
| rightEyeOpenProbability | `Float` | The right eye open probability. |
| hasRightEyeOpenProbability | `Bool` | Indicates whether a right eye open probability is available. |
| smilingProbability | `Float` | The smiling probability. |
| hasSmilingProbability | `Bool` | Indicates whether a smiling probability is available. |
| headEulerAngleX | `Float` | The angle in degrees that indicate the vertical head direction. See [Head Movements](#headmovements). |
| hasHeadEulerAngleX | `Bool` | Indicates whether the detector found the head x euler angle. |
| headEulerAngleY | `Float` | The angle in degrees that indicate the horizontal head direction. See [Head Movements](#headmovements). |
| hasHeadEulerAngleY | `Bool` | Indicates whether the detector found the head y euler angle. |
| headEulerAngleZ | `Float` | The angle in degrees that indicate the tilt head direction. See [Head Movements](#headmovements). |
| hasHeadEulerAngleZ | `Bool` | Indicates whether the detector found the head z euler angle. |
| leftEyeOpenProbability | `Float?` | The left eye open probability. |
| rightEyeOpenProbability | `Float?` | The right eye open probability. |
| smilingProbability | `Float?` | The smiling probability. |
| headEulerAngleX | `Float?` | The angle in degrees that indicate the vertical head direction. See [Head Movements](#headmovements). |
| headEulerAngleY | `Float?` | The angle in degrees that indicate the horizontal head direction. See [Head Movements](#headmovements). |
| headEulerAngleZ | `Float?` | The angle in degrees that indicate the tilt head direction. See [Head Movements](#headmovements). |
| contours | `[CGPoint]` | List of points that represents the shape of the detected face. |

#### Head Movements
Expand Down
2 changes: 1 addition & 1 deletion YoonitFacefy.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Pod::Spec.new do |spec|
#

spec.name = "YoonitFacefy"
spec.version = "1.0.3"
spec.version = "1.0.4"
spec.summary = "The face detection's module for iOS with a lot of awesome features"

# This description is used to generate tags and improve search results.
Expand Down
14 changes: 7 additions & 7 deletions YoonitFacefy.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
6176EF25252CFEE000F4D4DD /* README.md */,
6176EF22252CFC9500F4D4DD /* LICENSE */,
6176EF1F252CFA4300F4D4DD /* YoonitFacefy.podspec */,
6176EEFA252CF9D200F4D4DD /* Info.plist */,
6176EEF8252CF9D200F4D4DD /* YoonitFacefy */,
6176EEF7252CF9D200F4D4DD /* Products */,
85073D94B694632C1A966E28 /* Pods */,
Expand All @@ -112,7 +113,6 @@
isa = PBXGroup;
children = (
5C0C6435254208E400EDF95B /* src */,
6176EEFA252CF9D200F4D4DD /* Info.plist */,
5CB4F8EE25CC7DDC001D3606 /* YoonitFacefy.h */,
);
path = YoonitFacefy;
Expand Down Expand Up @@ -414,16 +414,16 @@
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = YoonitFacefy/Info.plist;
INFOPLIST_FILE = "$(SRCROOT)/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.0.3;
PRODUCT_BUNDLE_IDENTIFIER = ai.cyberlabs.YoonitFacefy;
MARKETING_VERSION = 1.0.4;
PRODUCT_BUNDLE_IDENTIFIER = com.yoonit.facefy;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SUPPORTS_MACCATALYST = NO;
Expand All @@ -444,16 +444,16 @@
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = YoonitFacefy/Info.plist;
INFOPLIST_FILE = "$(SRCROOT)/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.0.3;
PRODUCT_BUNDLE_IDENTIFIER = ai.cyberlabs.YoonitFacefy;
MARKETING_VERSION = 1.0.4;
PRODUCT_BUNDLE_IDENTIFIER = com.yoonit.facefy;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SUPPORTS_MACCATALYST = NO;
Expand Down
44 changes: 13 additions & 31 deletions YoonitFacefy/src/FaceDetected.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,49 +14,31 @@ import UIKit
public class FaceDetected {

public var boundingBox: CGRect
public var leftEyeOpenProbability: Float
public var hasLeftEyeOpenProbability: Bool
public var rightEyeOpenProbability: Float
public var hasRightEyeOpenProbability: Bool
public var smilingProbability: Float
public var hasSmilingProbability: Bool
public var headEulerAngleX: Float
public var hasHeadEulerAngleX: Bool
public var headEulerAngleY: Float
public var hasHeadEulerAngleY: Bool
public var headEulerAngleZ: Float
public var hasHeadEulerAngleZ: Bool
public var leftEyeOpenProbability: Float?
public var rightEyeOpenProbability: Float?
public var smilingProbability: Float?
public var headEulerAngleX: Float?
public var headEulerAngleY: Float?
public var headEulerAngleZ: Float?
public var contours: [CGPoint] = []

init(
boundingBox: CGRect,
leftEyeOpenProbability: Float,
hasLeftEyeOpenProbability: Bool,
rightEyeOpenProbability: Float,
hasRightEyeOpenProbability: Bool,
smilingProbability: Float,
hasSmilingProbability: Bool,
headEulerAngleX: Float,
hasHeadEulerAngleX: Bool,
headEulerAngleY: Float,
hasHeadEulerAngleY: Bool,
headEulerAngleZ: Float,
hasHeadEulerAngleZ: Bool,
leftEyeOpenProbability: Float?,
rightEyeOpenProbability: Float?,
smilingProbability: Float?,
headEulerAngleX: Float?,
headEulerAngleY: Float?,
headEulerAngleZ: Float?,
contours: [CGPoint]
) {
self.boundingBox = boundingBox
self.leftEyeOpenProbability = leftEyeOpenProbability
self.hasLeftEyeOpenProbability = hasLeftEyeOpenProbability
self.rightEyeOpenProbability = rightEyeOpenProbability
self.hasRightEyeOpenProbability = hasRightEyeOpenProbability
self.smilingProbability = smilingProbability
self.hasSmilingProbability = hasSmilingProbability
self.headEulerAngleX = headEulerAngleX
self.hasHeadEulerAngleX = hasHeadEulerAngleX
self.headEulerAngleY = headEulerAngleY
self.hasHeadEulerAngleY = hasHeadEulerAngleY
self.headEulerAngleZ = headEulerAngleZ
self.hasHeadEulerAngleZ = hasHeadEulerAngleZ
self.headEulerAngleZ = headEulerAngleZ
self.contours = contours
}
}
2 changes: 0 additions & 2 deletions YoonitFacefy/src/Facefy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
//

import Foundation
import UIKit
import Vision

public class Facefy {

Expand Down
31 changes: 15 additions & 16 deletions YoonitFacefy/src/FacefyController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,17 @@
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
//

import Foundation
import UIKit
import Vision
import MLKit

public class FacefyController {

private let faceDetector: FaceDetector

init() {
let options: FaceDetectorOptions = FaceDetectorOptions()
let options = FaceDetectorOptions()
options.performanceMode = .fast
options.landmarkMode = .all
options.landmarkMode = .none
options.contourMode = .all
options.classificationMode = .all

Expand Down Expand Up @@ -63,22 +61,23 @@ public class FacefyController {
}
}
}

let rightEyeOpenProbability: Float? = face.hasRightEyeOpenProbability ? Float(face.rightEyeOpenProbability) : nil
let leftEyeOpenProbability: Float? = face.hasLeftEyeOpenProbability ? Float(face.leftEyeOpenProbability) : nil
let smilingProbability: Float? = face.hasSmilingProbability ? Float(face.smilingProbability) : nil
let headEulerAngleX: Float? = face.hasHeadEulerAngleX ? Float(face.headEulerAngleX) : nil
let headEulerAngleY: Float? = face.hasHeadEulerAngleY ? Float(face.headEulerAngleY) : nil
let headEulerAngleZ: Float? = face.hasHeadEulerAngleZ ? Float(face.headEulerAngleZ) : nil

onSuccess(
FaceDetected(
boundingBox: face.frame,
leftEyeOpenProbability: Float(face.rightEyeOpenProbability),
hasLeftEyeOpenProbability: face.hasRightEyeOpenProbability,
rightEyeOpenProbability: Float(face.leftEyeOpenProbability),
hasRightEyeOpenProbability: face.hasLeftEyeOpenProbability,
smilingProbability: Float(face.smilingProbability),
hasSmilingProbability: face.hasSmilingProbability,
headEulerAngleX: Float(face.headEulerAngleX),
hasHeadEulerAngleX: face.hasHeadEulerAngleX,
headEulerAngleY: Float(face.headEulerAngleY),
hasHeadEulerAngleY: face.hasHeadEulerAngleY,
headEulerAngleZ: Float(face.headEulerAngleZ),
hasHeadEulerAngleZ: face.hasHeadEulerAngleZ,
leftEyeOpenProbability: rightEyeOpenProbability,
rightEyeOpenProbability: leftEyeOpenProbability,
smilingProbability: smilingProbability,
headEulerAngleX: headEulerAngleX,
headEulerAngleY: headEulerAngleY,
headEulerAngleZ: headEulerAngleZ,
contours: faceContours
)
)
Expand Down

0 comments on commit 2e18b2b

Please sign in to comment.