Skip to content

Commit

Permalink
Merge pull request #3 from cyberlabsai/refactor/api
Browse files Browse the repository at this point in the history
Refactor/api
  • Loading branch information
TeruyaHaroldo authored Jul 13, 2021
2 parents d61c07e + b902de5 commit 4e9217f
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 43 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 @@ -628,7 +628,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.0.3;
MARKETING_VERSION = 0.0.4;
PRODUCT_BUNDLE_IDENTIFIER = ai.cyberlabs.perselitedemo;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -661,7 +661,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.0.3;
MARKETING_VERSION = 0.0.4;
PRODUCT_BUNDLE_IDENTIFIER = ai.cyberlabs.perselitedemo;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@
<color key="tintColor" systemColor="systemGreenColor"/>
</imageView>
</subviews>
<color key="backgroundColor" white="1" alpha="0.5" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="xxV-i1-DII">
<rect key="frame" x="206" y="512" width="200" height="200"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ class PerseLiteCameraViewController:
)
)
let image = UIImage(contentsOfFile: subpath)
self.faceImageView.image = image

self.perseLite.face.detect(imagePath) {
detectResponse in

if detectResponse.totalFaces == 0 {
self.reset()
return
}

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

self.setSpoofingValidation(valid: face.livenessScore >= 0.7)
Expand Down Expand Up @@ -108,7 +108,7 @@ class PerseLiteCameraViewController:
)
} onError: {
status, error in
debugPrint(error)
debugPrint(status)
self.reset()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,6 @@ class PerseLiteDetectViewController:
boundingBox.description
))
}
self.tablecells.append(TableCell(
"Confidence",
face.confidence
))
self.tablecells.append(TableCell("Face Metrics \(i)"))
self.tablecells.append(TableCell(
"Overexpose",
Expand All @@ -148,10 +144,6 @@ class PerseLiteDetectViewController:
face.faceMetrics.sharpness
))
}
self.tablecells.append(TableCell(
"Image Token",
detectResponse.imageToken ?? ""
))
self.tablecells.append(TableCell("Image Metrics"))
self.tablecells.append(TableCell(
"Overexpose",
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.1):
- PerseLite (0.0.3):
- 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: 4b56169aa2eb8717c4906b3fc600b3d73a1ba1fb
PerseLite: 87870df4696e3eb1f5ab347a7248bebdbd0069c1
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.0.3"
spec.version = "0.0.4"
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
22 changes: 7 additions & 15 deletions PerseLite.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
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 /* FaceResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CBA83CA264487D800A6E314 /* FaceResponse.swift */; };
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 */; };
D6A5F631B2DAEAE767453F1F /* Pods_PerseLite.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BC7DF46DA52525E48DF71642 /* Pods_PerseLite.framework */; };
Expand All @@ -39,7 +39,7 @@
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 /* FaceResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FaceResponse.swift; 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>"; };
6176EEF6252CF9D200F4D4DD /* PerseLite.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = PerseLite.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6176EEFA252CF9D200F4D4DD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand All @@ -63,28 +63,20 @@
5C0C6435254208E400EDF95B /* src */ = {
isa = PBXGroup;
children = (
5CBA83C9264487A400A6E314 /* model */,
5CBA83CA264487D800A6E314 /* Response.swift */,
5C06E5CE25D1FED400E6770F /* PerseLite.swift */,
5C6BB28D2642C9CF007BB893 /* Face.swift */,
5CE124C1264E108600D484A1 /* Util.swift */,
);
path = src;
sourceTree = "<group>";
};
5CBA83C9264487A400A6E314 /* model */ = {
isa = PBXGroup;
children = (
5CBA83CA264487D800A6E314 /* FaceResponse.swift */,
);
path = model;
sourceTree = "<group>";
};
6176EEEC252CF9D200F4D4DD = {
isa = PBXGroup;
children = (
5C6CEE0A268B95D1008E0F2F /* LICENSE */,
6176EFA7252E476000F4D4DD /* Example */,
6176EEFA252CF9D200F4D4DD /* Info.plist */,
5C6CEE0A268B95D1008E0F2F /* LICENSE */,
5C6BB2732641D99C007BB893 /* PerseLite.podspec */,
5C6BB27D2641EC14007BB893 /* Podfile */,
5C2FFC06266E5715000DD190 /* README.md */,
Expand Down Expand Up @@ -250,7 +242,7 @@
buildActionMask = 2147483647;
files = (
5C6BB28E2642C9CF007BB893 /* Face.swift in Sources */,
5CBA83CB264487D800A6E314 /* FaceResponse.swift in Sources */,
5CBA83CB264487D800A6E314 /* Response.swift in Sources */,
5C06E5CF25D1FED400E6770F /* PerseLite.swift in Sources */,
5CE124C2264E108600D484A1 /* Util.swift in Sources */,
);
Expand Down Expand Up @@ -400,7 +392,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 0.0.3;
MARKETING_VERSION = 0.0.4;
PRODUCT_BUNDLE_IDENTIFIER = ai.cyberlabs.perselite;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -430,7 +422,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 0.0.3;
MARKETING_VERSION = 0.0.4;
PRODUCT_BUNDLE_IDENTIFIER = ai.cyberlabs.perselite;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand Down
6 changes: 4 additions & 2 deletions PerseLite/src/Face.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ public class Face {

if uploadResponse.statusCode == 200 {
do {
guard let detectResponse: DetectResponse = try result.data?.detectResponse() else {
guard var detectResponse: DetectResponse = try result.data?.detectResponse() else {
return
}
detectResponse.raw = result.value
onSuccess(detectResponse)
} catch let error {
onError("\(error)", "")
Expand Down Expand Up @@ -138,9 +139,10 @@ public class Face {
switch uploadResponse.statusCode {
case 200:
do {
guard let compareResponse: CompareResponse = try result.data?.compareResponse() else {
guard var compareResponse: CompareResponse = try result.data?.compareResponse() else {
return
}
compareResponse.raw = result.value
onSuccess(compareResponse)
} catch let error {
onError("\(error)", "")
Expand Down
2 changes: 1 addition & 1 deletion PerseLite/src/PerseLite.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import UIKit

public class PerseLite {
open class PerseLite {

public struct Error {
public static let INVALID_IMAGE_PATH = "INVALID_IMAGE_PATH"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public struct Compare402Response: Decodable {
public struct CompareResponse: Decodable {
public let status: Int
public let similarity: Float
public let imageTokens: Array<String>?
public let timeTaken: Float
public var raw: String?
}

public struct LandmarksResponse: Decodable {
Expand All @@ -27,7 +27,6 @@ public struct MetricsResponse: Decodable {

public struct FaceResponse: Decodable {
public let boundingBox: Array<Int>
public let confidence: Float
public let faceMetrics: MetricsResponse
public let landmarks: LandmarksResponse
public let livenessScore: Float
Expand All @@ -37,7 +36,7 @@ public struct DetectResponse: Decodable {
public let totalFaces: Int
public let faces: Array<FaceResponse>
public let imageMetrics: MetricsResponse
public let imageToken: String?
public let status: Int
public let timeTaken: Float
public var raw: String?
}
2 changes: 0 additions & 2 deletions PerseLite/src/Util.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ extension Data {
DetectResponse.self,
from: self
)

return response
} catch(let error) {
throw error
Expand All @@ -38,7 +37,6 @@ extension Data {
CompareResponse.self,
from: self
)

return response
} catch(let error) {
throw error
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ func compare(
| Attribute | Type | Description
| - | - | -
| similarity | `Float` | Similarity between faces. Closer to `1` is better.
| imageTokens | `Array<String>` | The image tokens array.
| timeTaken | `Float` | Time taken to analyze the image.
| raw | `String?` | The API response in string.

#### DetectResponse

Expand All @@ -269,15 +269,14 @@ func compare(
| totalFaces | `Int` | Total of faces in the image.
| faces | `Array<FaceResponse>` | Array of [FaceResponse](#faceresponse).
| imageMetrics | [MetricsResponse](#metricsresponse) | Metrics of the detected image.
| imageToken | `String` | The image token.
| timeTaken | `Float` | Time taken to analyze the image.
| raw | `String?` | The API response in string.

#### FaceResponse

| Attribute | Type | Description
| - | - | -
| landmarks | [LandmarksResponse](#landmarksresponse) | Detected face landmarks.
| confidence | `Int` | Confidence that the face is a real face.
| boundingBox | `Array<Int>` | Array with the four values of the face bounding box. The coordinates `x`, `y` and the dimension `width` and `height` respectively.
| faceMetrics | [MetricsResponse](#metricsresponse) | Metrics of the detecting face.
| livenessScore | `Long` | Confidence that a detected face is from a live person (1 means higher confidence).
Expand Down

0 comments on commit 4e9217f

Please sign in to comment.