Perse SDK Lite iOS
From CyberLabs.AI.
Ready to go biometric verification for the internet.
The Perse CocoaPods SDK Lite:
- Top notch facial detection model;
- Anti-spoofing;
- Feedback on image quality;
- Compare the similarity between two faces;
- Doesn't store any photos;
For more details, you can see the Official Perse.
Soon voice biometric verification.
Content of Table
About
This SDK provides abstracts the communication with the Perse's API endpoints and also convert the response from json to a pre-defined responses.
Want to test the endpoints?
You can test our endpoints using this Swagger UI Playground.
Want to test a web live demo?
You can test our web live demos in the CyberLabs.AI CodePen or in the Perse Oficial Docs. Do not forget your API Key.
Want to try a backend client?
We have some examples in
Python
,Go
andjavaScript
. You can see documented here.
Get Started
Install
-
Create a Podfile. You may need install CocoaPods in your environment.
-
Add the following line to your
Podfile
file:
pod 'PerseLite'
- And run in the project root the following command line:
pod install
- Now, you can open and build your project with the extension
.xcworkspace
;
How to create a Xcode project with CocoaPods?
To create a Xcode project with CocoaPods you can see in the Official CocoaPods Guide.
API Key
Perse API authenticates your requests using an API Key.
We are currently in Alpha. So you can get your API Key:
- Sending an email to [email protected];
- Or in the Perse official site https://www.getperse.com/;
Demo
We have a Demo in this repository for you:
- Feel free to change the Demo code;
- Not forget to get your API KEY;
- To run, the Demo, it is necessary to follow the Install steps;
Usage
Face Detect
Detect allows you process images with the intent of detecting human faces.
import PerseLite
func detect(_ file: String) {
let perseLite = PerseLite(apiKey: "API_KEY")
perseLite.face.detect(filePath) {
detectResponse in
debugPrint(detectResponse)
} onError: {
error in
debugPrint(error)
}
}
Face Compare
Compare accepts two sources for similarity comparison.
import PerseLite
func compare(
_ firstFile: String,
_ secondFile: String
) {
let perseLite = PerseLite(apiKey: "API_KEY")
perseLite.face.compare(
firstFilePath,
secondFilePath
) {
compareResponse in
debugPrint(compareResponse)
} onError: {
error in
debugPrint(error)
}
}
Camera Integration
Here we have a example in code how to detect a face from a camera. See the complete code in the Demo application.
Just follow the Installation in the Yoonit Camera
.
import UIKit
import PerseLite
import YoonitCamera
class PerseLiteCameraViewController:
UIViewController,
CameraEventListenerDelegate
{
override func viewDidLoad() {
super.viewDidLoad()
self.cameraView.cameraEventListener = self
self.cameraView.startPreview()
self.cameraView.setSaveImageCaptured(true)
self.cameraView.setTimeBetweenImages(300)
self.cameraView.startCaptureType("frame")
}
func onImageCaptured(
_ type: String,
_ count: Int,
_ total: Int,
_ imagePath: String,
_ darkness: NSNumber?,
_ lightness: NSNumber?,
_ sharpness: NSNumber?
) {
self.perseLite.face.detect(imagePath) {
detectResponse in
debugPrint(detectResponse)
} onError: {
error in
debugPrint(error)
}
}
...
}
Running Tests
Important:
You access it by clicking its icon in the navigator selector bar, located between the issue navigator and the debug navigator. When you have a project with a suite of tests defined, you see a navigator view similar to the one shown here.
API
This section describes the Perse SDK Lite iOS API's, methods, your responses and possible errors.
Methods
The Perse is in alpha
version and for now, only the Face
module is available.
face.detect
- Has the intent of detecting any number of human faces;
- Can use this resource to evaluate the overall quality of the image;
- The input can be the image file path or his Data;
- The
onSuccess
return type is DetectResponse struct; - The
onError
return type can see in the Errors;
func detect(
_ filePath: String,
onSuccess: @escaping (DetectResponse) -> Void,
onError: @escaping (String, String) -> Void
)
func detect(
_ data: Data,
onSuccess: @escaping (DetectResponse) -> Void,
onError: @escaping (String, String) -> Void
)
face.compare
- Accepts two sources for similarity comparison;
- The inputs can be the image file paths or his Data's;
- The
onSuccess
return type is CompareResponse struct; - The
onError
return type can see in the Errors;
func compare(
_ firstFilePath: String,
_ secondFilePath: String,
onSuccess: @escaping (CompareResponse) -> Void,
onError: @escaping (String, String) -> Void
)
func compare(
_ firstFile: Data,
_ secondFile: Data,
onSuccess: @escaping (CompareResponse) -> Void,
onError: @escaping (String, String) -> Void
)
Tip
We recommend considering a match when similarity is above
71
.
Responses
CompareResponse
Attribute | Type | Description |
---|---|---|
similarity | Float |
Similarity between faces. Closer to 1 is better. |
timeTaken | Float |
Time taken to analyze the image. |
raw | String? |
The API response in string. |
DetectResponse
Attribute | Type | Description |
---|---|---|
totalFaces | Int |
Total of faces in the image. |
faces | Array |
Array of FaceResponse. |
imageMetrics | MetricsResponse | Metrics of the detected image. |
timeTaken | Float |
Time taken to analyze the image. |
raw | String? |
The API response in string. |
FaceResponse
Attribute | Type | Description |
---|---|---|
landmarks | LandmarksResponse | Detected face landmarks. |
boundingBox | Array |
Array with the four values of the face bounding box. The coordinates x , y and the dimension width and height respectively. |
faceMetrics | MetricsResponse | Metrics of the detecting face. |
livenessScore | Long |
Confidence that a detected face is from a live person (1 means higher confidence). |
MetricsResponse
Attribute | Type | Description |
---|---|---|
underexpose | Float |
Indicates loss of shadow detail. Closer to 0 is better. |
overexpose | Float |
Indicates loss of highlight detail. Closer to 0 is better. |
sharpness | Float |
Indicates intensity of motion blur. Closer to 1 is better. |
LandmarksResponse
Attribute | Type | Description |
---|---|---|
rightEye | Array |
Right eye landmarks. |
leftEye | Array |
Left eye landmarks. |
nose | Array |
Nose landmarks. |
mouthRight | Array |
Right side of mouth landmarks. |
mouthLeft | Array |
Left side of mouth landmarks. |
Errors
The onError
:
- First parameter is the
Error Code
; - Second parameter is a raw text message;
Error Code | Description |
---|---|
400 | The request was unacceptable, often due to missing a required parameter. |
401 | API key is missing or invalid. |
402 | The parameters were valid but the request failed. |
415 | The content type or encoding is not valid. |
To Contribute and Make It Better
Clone the repo, change what you want and send PR.
For commit messages we use Conventional Commits.
Contributions are always welcome!
Made with