Skip to content

Commit

Permalink
Merge pull request #5 from cyberlabsai/refactor/api
Browse files Browse the repository at this point in the history
Refactor api
  • Loading branch information
TeruyaHaroldo authored Jul 28, 2021
2 parents 6c7c558 + d58a94a commit df3bf04
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 40 deletions.
4 changes: 2 additions & 2 deletions Example/PerseLiteDemo/PerseLiteDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.1.0;
MARKETING_VERSION = 0.1.1;
PRODUCT_BUNDLE_IDENTIFIER = ai.cyberlabs.perselitedemo;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -658,7 +658,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.1.0;
MARKETING_VERSION = 0.1.1;
PRODUCT_BUNDLE_IDENTIFIER = ai.cyberlabs.perselitedemo;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
12 changes: 6 additions & 6 deletions Example/PerseLiteDemo/PerseLiteDemo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@
<color key="textColor" systemColor="systemGrayColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Face Underexpose:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Gva-6e-ZaQ">
<rect key="frame" x="35" y="95" width="147" height="21"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Face Underexposure:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Gva-6e-ZaQ">
<rect key="frame" x="35" y="95" width="162" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" systemColor="systemGrayColor"/>
Expand All @@ -331,7 +331,7 @@
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="-" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="wTh-wl-QgW">
<rect key="frame" x="190" y="95" width="216" height="21"/>
<rect key="frame" x="205" y="95" width="201" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
Expand All @@ -345,7 +345,7 @@
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="-" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="KXB-IT-YlQ">
<rect key="frame" x="201" y="153" width="205" height="21"/>
<rect key="frame" x="216" y="153" width="190" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
Expand All @@ -358,8 +358,8 @@
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Image Underexpose:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="OAp-8m-cIc">
<rect key="frame" x="35" y="153" width="158" height="21"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Image Underexposure:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="OAp-8m-cIc">
<rect key="frame" x="35" y="153" width="173" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" systemColor="systemGrayColor"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ class PerseLiteCameraViewController:
self.cameraView.setSaveImageCaptured(true)
self.cameraView.setDetectionBox(true)
self.cameraView.setFaceContours(true)
self.cameraView.detectionTopSize = 0.2
self.cameraView.detectionRightSize = 0.2
self.cameraView.detectionBottomSize = 0.2
self.cameraView.detectionLeftSize = 0.2
self.cameraView.setTimeBetweenImages(1000)
self.cameraView.startCaptureType("face")
}
Expand Down Expand Up @@ -82,30 +86,30 @@ class PerseLiteCameraViewController:
let face: FaceResponse = detectResponse.faces[0]

self.setSpoofingValidation(
valid: face.livenessScore >= detectResponse.defaultThresholds.livenessThreshold
valid: face.livenessScore >= detectResponse.defaultThresholds.liveness
)
self.handleDisplayProbability(
label: self.faceUnderexposeLabel,
icon: self.faceUnderexposeIcon,
validation: face.faceMetrics.underexpose > detectResponse.defaultThresholds.underexposerThreshold,
value: face.faceMetrics.underexpose
validation: face.faceMetrics.underexposure > detectResponse.defaultThresholds.underexposure,
value: face.faceMetrics.underexposure
)
self.handleDisplayProbability(
label: self.faceSharpnessLabel,
icon: self.faceSharpnessIcon,
validation: face.faceMetrics.sharpness < detectResponse.defaultThresholds.sharpnessThreshold,
validation: face.faceMetrics.sharpness < detectResponse.defaultThresholds.sharpness,
value: face.faceMetrics.sharpness
)
self.handleDisplayProbability(
label: self.imageUnderexposeLabel,
icon: self.imageUnderexposeIcon,
validation: detectResponse.imageMetrics.underexpose > detectResponse.defaultThresholds.underexposerThreshold,
value: detectResponse.imageMetrics.underexpose
validation: detectResponse.imageMetrics.underexposure > detectResponse.defaultThresholds.underexposure,
value: detectResponse.imageMetrics.underexposure
)
self.handleDisplayProbability(
label: self.imageSharpnessLabel,
icon: self.imageSharpnessIcon,
validation: detectResponse.imageMetrics.sharpness < detectResponse.defaultThresholds.sharpnessThreshold,
validation: detectResponse.imageMetrics.sharpness < detectResponse.defaultThresholds.sharpness,
value: detectResponse.imageMetrics.sharpness
)
} onError: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ class PerseLiteDetectViewController:
}
self.tablecells.append(TableCell("Face Metrics \(i)"))
self.tablecells.append(TableCell(
"Overexpose",
face.faceMetrics.overexpose
"Overexposure",
face.faceMetrics.overexposure
))
self.tablecells.append(TableCell(
"Underexpose",
face.faceMetrics.underexpose
face.faceMetrics.underexposure
))
self.tablecells.append(TableCell(
"Sharpness",
Expand All @@ -146,12 +146,12 @@ class PerseLiteDetectViewController:
}
self.tablecells.append(TableCell("Image Metrics"))
self.tablecells.append(TableCell(
"Overexpose",
detectResponse.imageMetrics.overexpose
"Overexposure",
detectResponse.imageMetrics.overexposure
))
self.tablecells.append(TableCell(
"Underexpose",
detectResponse.imageMetrics.underexpose
detectResponse.imageMetrics.underexposure
))
self.tablecells.append(TableCell(
"Sharpness",
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.4):
- PerseLite (0.1.1):
- 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: ae708d19380479aade7bd4bcbaf4a13f3595ca48
PerseLite: c2e15268b26a31196ef651597309d49a9008e2ce
PromisesObjC: 3113f7f76903778cf4a0586bd1ab89329a0b7b97
Protobuf: 7327d4444215b5f18e560a97f879ff5503c4581c
YoonitCamera: b42e7405363e882952dc5575e74cc40ec088d989
Expand Down
2 changes: 1 addition & 1 deletion PerseLite.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Pod::Spec.new do |spec|
# ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #

spec.name = "PerseLite"
spec.version = "0.1.0"
spec.version = "0.1.1"
spec.summary = "Perse SDK Lite iOS"
spec.description = <<-DESC
"This SDK provides abstracts the communication with the Perse's API endpoints and also convert the response from json to a pre-defined responses."
Expand Down
4 changes: 2 additions & 2 deletions PerseLite.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 0.1.0;
MARKETING_VERSION = 0.1.1;
PRODUCT_BUNDLE_IDENTIFIER = ai.cyberlabs.perselite;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -442,7 +442,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 0.1.0;
MARKETING_VERSION = 0.1.1;
PRODUCT_BUNDLE_IDENTIFIER = ai.cyberlabs.perselite;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand Down
8 changes: 3 additions & 5 deletions PerseLite/src/Face.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,12 @@ public class Face {
guard let uploadResponse: HTTPURLResponse = result.response else {
return
}

if uploadResponse.statusCode == 200 {
do {
guard var detectResponse: DetectResponse = try result.data?.detectResponse() else {
guard let detectResponse: DetectResponse = try result.data?.detectResponse() else {
return
}
detectResponse.raw = result.value
onSuccess(detectResponse)
} catch let error {
onError("\(error)", "")
Expand Down Expand Up @@ -139,10 +138,9 @@ public class Face {
switch uploadResponse.statusCode {
case 200:
do {
guard var compareResponse: CompareResponse = try result.data?.compareResponse() else {
guard let compareResponse: CompareResponse = try result.data?.compareResponse() else {
return
}
compareResponse.raw = result.value
onSuccess(compareResponse)
} catch let error {
onError("\(error)", "")
Expand Down
16 changes: 7 additions & 9 deletions PerseLite/src/Response.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ public struct Compare402Response: Decodable {
}

public struct CompareThreshold: Decodable {
public let similarityThreshold: Float
public let similarity: 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?
}

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

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

public struct FaceResponse: Decodable {
Expand All @@ -38,10 +37,10 @@ public struct FaceResponse: Decodable {
}

public struct DetectThresholds: Decodable {
public let overexposureThreshold: Float
public let sharpnessThreshold: Float
public let underexposerThreshold: Float
public let livenessThreshold: Float
public let overexposure: Float
public let sharpness: Float
public let underexposure: Float
public let liveness: Float
}

public struct DetectResponse: Decodable {
Expand All @@ -51,5 +50,4 @@ public struct DetectResponse: Decodable {
public let status: Int
public let timeTaken: Float
public let defaultThresholds: DetectThresholds
public var raw: String?
}

0 comments on commit df3bf04

Please sign in to comment.