Skip to content

Commit

Permalink
Merge pull request #4 from cyberlabsai/feature/threshold
Browse files Browse the repository at this point in the history
Feature Threshold API
  • Loading branch information
TeruyaHaroldo committed Jul 22, 2021
2 parents 4e9217f + edb6932 commit 9d74ddf
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 306 deletions.
3 changes: 0 additions & 3 deletions Example/PerseLiteDemo/PerseLiteDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
5C41242826554C8C00C02049 /* PerseLiteUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PerseLiteUtils.swift; sourceTree = "<group>"; };
5C412452265594DA00C02049 /* PerseLiteFaceCompareWithFileTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PerseLiteFaceCompareWithFileTests.swift; sourceTree = "<group>"; };
5C73AAD42681184E0028435B /* PerseLiteCameraViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PerseLiteCameraViewController.swift; sourceTree = "<group>"; };
5CB416A82652EEF600B7D1EC /* Development.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Development.xcconfig; sourceTree = "<group>"; };
5CB416AA2652F08E00B7D1EC /* Environment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Environment.swift; sourceTree = "<group>"; };
5CE123D7264AF36600D484A1 /* FileUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileUtils.swift; sourceTree = "<group>"; };
5CE123EC264B087800D484A1 /* PerseLiteCompareViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PerseLiteCompareViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -135,7 +134,6 @@
6176EFB5252E496C00F4D4DD = {
isa = PBXGroup;
children = (
5CB416A82652EEF600B7D1EC /* Development.xcconfig */,
5C06E54725D1F09A00E6770F /* Podfile */,
6176EFC0252E496D00F4D4DD /* PerseLiteDemo */,
5CF64E682653F51F004763E3 /* PerseLiteDemoTests */,
Expand Down Expand Up @@ -484,7 +482,6 @@
};
6176EFD0252E496F00F4D4DD /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 5CB416A82652EEF600B7D1EC /* Development.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,33 +77,35 @@ class PerseLiteCameraViewController:
self.reset()
return
}

self.faceImageView.image = image
let face: FaceResponse = detectResponse.faces[0]

self.setSpoofingValidation(valid: face.livenessScore >= 0.7)
self.setSpoofingValidation(
valid: face.livenessScore >= detectResponse.defaultThresholds.livenessThreshold
)
self.handleDisplayProbability(
label: self.faceUnderexposeLabel,
icon: self.faceUnderexposeIcon,
validation: face.faceMetrics.underexpose > 0.7,
validation: face.faceMetrics.underexpose > detectResponse.defaultThresholds.underexposerThreshold,
value: face.faceMetrics.underexpose
)
self.handleDisplayProbability(
label: self.faceSharpnessLabel,
icon: self.faceSharpnessIcon,
validation: face.faceMetrics.sharpness < 0.07,
validation: face.faceMetrics.sharpness < detectResponse.defaultThresholds.sharpnessThreshold,
value: face.faceMetrics.sharpness
)
self.handleDisplayProbability(
label: self.imageUnderexposeLabel,
icon: self.imageUnderexposeIcon,
validation: detectResponse.imageMetrics.underexpose > 0.7,
validation: detectResponse.imageMetrics.underexpose > detectResponse.defaultThresholds.underexposerThreshold,
value: detectResponse.imageMetrics.underexpose
)
self.handleDisplayProbability(
label: self.imageSharpnessLabel,
icon: self.imageSharpnessIcon,
validation: detectResponse.imageMetrics.sharpness < 0.07,
validation: detectResponse.imageMetrics.sharpness < detectResponse.defaultThresholds.sharpnessThreshold,
value: detectResponse.imageMetrics.sharpness
)
} onError: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class PerseLiteDetectViewController:
guard let faces = detectResponse.faces as Array<FaceResponse>? else {
return
}

var i = 0
for face in faces {
i = i + 1
Expand Down
4 changes: 2 additions & 2 deletions Example/PerseLiteDemo/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ PODS:
- nanopb/encode (= 2.30908.0)
- nanopb/decode (2.30908.0)
- nanopb/encode (2.30908.0)
- PerseLite (0.0.3):
- PerseLite (0.0.4):
- Alamofire (~> 5.2)
- PromisesObjC (1.2.12)
- Protobuf (3.17.0)
Expand Down Expand Up @@ -100,7 +100,7 @@ SPEC CHECKSUMS:
MLKitFaceDetection: 5b92261dd6e4205e3dab0df62537ac3f4e90e5db
MLKitVision: 51385878c9100024478971856510f9271ff555b5
nanopb: a0ba3315591a9ae0a16a309ee504766e90db0c96
PerseLite: 87870df4696e3eb1f5ab347a7248bebdbd0069c1
PerseLite: ae708d19380479aade7bd4bcbaf4a13f3595ca48
PromisesObjC: 3113f7f76903778cf4a0586bd1ab89329a0b7b97
Protobuf: 7327d4444215b5f18e560a97f879ff5503c4581c
YoonitCamera: b42e7405363e882952dc5575e74cc40ec088d989
Expand Down
28 changes: 24 additions & 4 deletions PerseLite.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
objects = {

/* Begin PBXBuildFile section */
5C004A2126A8A8C900D6DD5F /* logo_cyberlabs.png in Resources */ = {isa = PBXBuildFile; fileRef = 5C004A1D26A8A8C900D6DD5F /* logo_cyberlabs.png */; };
5C004A2226A8A8C900D6DD5F /* testing_with_xcode.png in Resources */ = {isa = PBXBuildFile; fileRef = 5C004A1E26A8A8C900D6DD5F /* testing_with_xcode.png */; };
5C004A4126A8B50400D6DD5F /* config.gif in Resources */ = {isa = PBXBuildFile; fileRef = 5C004A3F26A8B50400D6DD5F /* config.gif */; };
5C004A4226A8B50400D6DD5F /* anti_spoof.gif in Resources */ = {isa = PBXBuildFile; fileRef = 5C004A4026A8B50400D6DD5F /* anti_spoof.gif */; };
5C06E5CF25D1FED400E6770F /* PerseLite.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C06E5CE25D1FED400E6770F /* PerseLite.swift */; };
5C2FFC07266E5715000DD190 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 5C2FFC06266E5715000DD190 /* README.md */; };
5C5056FF260BA65A00286F91 /* PerseLite.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CB4F8EE25CC7DDC001D3606 /* PerseLite.h */; settings = {ATTRIBUTES = (Public, ); }; };
5C6BB2742641D99C007BB893 /* PerseLite.podspec in Resources */ = {isa = PBXBuildFile; fileRef = 5C6BB2732641D99C007BB893 /* PerseLite.podspec */; };
5C6BB27E2641EC14007BB893 /* Podfile in Resources */ = {isa = PBXBuildFile; fileRef = 5C6BB27D2641EC14007BB893 /* Podfile */; };
5C6BB28E2642C9CF007BB893 /* Face.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C6BB28D2642C9CF007BB893 /* Face.swift */; };
5C6CEE0B268B95D1008E0F2F /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = 5C6CEE0A268B95D1008E0F2F /* LICENSE */; };
5C86E4ED268B5F4E00AD0B3B /* perseLite.gif in Resources */ = {isa = PBXBuildFile; fileRef = 5C86E4EC268B5F4E00AD0B3B /* perseLite.gif */; };
5CBA83CB264487D800A6E314 /* Response.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CBA83CA264487D800A6E314 /* Response.swift */; };
5CE124C2264E108600D484A1 /* Util.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CE124C1264E108600D484A1 /* Util.swift */; };
6176EFA8252E476000F4D4DD /* Example in Resources */ = {isa = PBXBuildFile; fileRef = 6176EFA7252E476000F4D4DD /* Example */; };
Expand All @@ -23,6 +26,10 @@

/* Begin PBXFileReference section */
4479E24251B210451180D9EC /* Pods-PerseLite.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PerseLite.debug.xcconfig"; path = "Target Support Files/Pods-PerseLite/Pods-PerseLite.debug.xcconfig"; sourceTree = "<group>"; };
5C004A1D26A8A8C900D6DD5F /* logo_cyberlabs.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = logo_cyberlabs.png; sourceTree = "<group>"; };
5C004A1E26A8A8C900D6DD5F /* testing_with_xcode.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = testing_with_xcode.png; sourceTree = "<group>"; };
5C004A3F26A8B50400D6DD5F /* config.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = config.gif; sourceTree = "<group>"; };
5C004A4026A8B50400D6DD5F /* anti_spoof.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = anti_spoof.gif; sourceTree = "<group>"; };
5C06E5CE25D1FED400E6770F /* PerseLite.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PerseLite.swift; sourceTree = "<group>"; };
5C2FFC06266E5715000DD190 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
5C65787D25D32FB2001171F8 /* libGoogleDataTransport.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libGoogleDataTransport.a; sourceTree = BUILT_PRODUCTS_DIR; };
Expand All @@ -37,7 +44,6 @@
5C6BB27D2641EC14007BB893 /* Podfile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Podfile; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.ruby; };
5C6BB28D2642C9CF007BB893 /* Face.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Face.swift; sourceTree = "<group>"; };
5C6CEE0A268B95D1008E0F2F /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
5C86E4EC268B5F4E00AD0B3B /* perseLite.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = perseLite.gif; sourceTree = "<group>"; };
5CB4F8EE25CC7DDC001D3606 /* PerseLite.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PerseLite.h; sourceTree = "<group>"; };
5CBA83CA264487D800A6E314 /* Response.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Response.swift; sourceTree = "<group>"; };
5CE124C1264E108600D484A1 /* Util.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Util.swift; sourceTree = "<group>"; };
Expand All @@ -60,6 +66,17 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
5C004A1C26A8A8C900D6DD5F /* assets */ = {
isa = PBXGroup;
children = (
5C004A4026A8B50400D6DD5F /* anti_spoof.gif */,
5C004A3F26A8B50400D6DD5F /* config.gif */,
5C004A1D26A8A8C900D6DD5F /* logo_cyberlabs.png */,
5C004A1E26A8A8C900D6DD5F /* testing_with_xcode.png */,
);
path = assets;
sourceTree = "<group>";
};
5C0C6435254208E400EDF95B /* src */ = {
isa = PBXGroup;
children = (
Expand All @@ -74,13 +91,13 @@
6176EEEC252CF9D200F4D4DD = {
isa = PBXGroup;
children = (
5C004A1C26A8A8C900D6DD5F /* assets */,
6176EFA7252E476000F4D4DD /* Example */,
6176EEFA252CF9D200F4D4DD /* Info.plist */,
5C6CEE0A268B95D1008E0F2F /* LICENSE */,
5C6BB2732641D99C007BB893 /* PerseLite.podspec */,
5C6BB27D2641EC14007BB893 /* Podfile */,
5C2FFC06266E5715000DD190 /* README.md */,
5C86E4EC268B5F4E00AD0B3B /* perseLite.gif */,
6176EEF8252CF9D200F4D4DD /* PerseLite */,
6176EEF7252CF9D200F4D4DD /* Products */,
85073D94B694632C1A966E28 /* Pods */,
Expand Down Expand Up @@ -200,10 +217,13 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
5C004A2226A8A8C900D6DD5F /* testing_with_xcode.png in Resources */,
5C004A2126A8A8C900D6DD5F /* logo_cyberlabs.png in Resources */,
5C004A4226A8B50400D6DD5F /* anti_spoof.gif in Resources */,
5C6CEE0B268B95D1008E0F2F /* LICENSE in Resources */,
5C6BB27E2641EC14007BB893 /* Podfile in Resources */,
5C004A4126A8B50400D6DD5F /* config.gif in Resources */,
5C6BB2742641D99C007BB893 /* PerseLite.podspec in Resources */,
5C86E4ED268B5F4E00AD0B3B /* perseLite.gif in Resources */,
5C2FFC07266E5715000DD190 /* README.md in Resources */,
6176EFA8252E476000F4D4DD /* Example in Resources */,
);
Expand Down
19 changes: 16 additions & 3 deletions PerseLite/src/Response.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ public struct Compare402Response: Decodable {
public let message: String
}

public struct CompareThreshold: Decodable {
public let similarityThreshold: Float
}

public struct CompareResponse: Decodable {
public let status: Int
public let similarity: Float
public let timeTaken: Float
public let defaultThreshold: CompareThreshold
public var raw: String?
}

Expand All @@ -20,9 +25,9 @@ public struct LandmarksResponse: Decodable {
}

public struct MetricsResponse: Decodable {
public let overexpose: Float;
public let sharpness: Float;
public let underexpose: Float;
public let overexpose: Float
public let sharpness: Float
public let underexpose: Float
}

public struct FaceResponse: Decodable {
Expand All @@ -32,11 +37,19 @@ public struct FaceResponse: Decodable {
public let livenessScore: Float
}

public struct DetectThresholds: Decodable {
public let overexposureThreshold: Float
public let sharpnessThreshold: Float
public let underexposerThreshold: Float
public let livenessThreshold: Float
}

public struct DetectResponse: Decodable {
public let totalFaces: Int
public let faces: Array<FaceResponse>
public let imageMetrics: MetricsResponse
public let status: Int
public let timeTaken: Float
public let defaultThresholds: DetectThresholds
public var raw: String?
}
Loading

0 comments on commit 9d74ddf

Please sign in to comment.