Skip to content

Commit

Permalink
Merge pull request #4 from cyberlabsai/feature/enroll
Browse files Browse the repository at this point in the history
User enroll
  • Loading branch information
TeruyaHaroldo authored Sep 1, 2021
2 parents deccacd + 40d0778 commit d50b1eb
Show file tree
Hide file tree
Showing 21 changed files with 393 additions and 283 deletions.
124 changes: 64 additions & 60 deletions Example/PerseDemo/PerseDemo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

57 changes: 28 additions & 29 deletions Example/PerseDemo/PerseDemo/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Example/PerseDemo/PerseDemo/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BASE_URL</key>
<string>$(BASE_URL)</string>
<key>API_KEY</key>
<string>$(API_KEY)</string>
<key>BASE_URL</key>
<string>$(BASE_URL)</string>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
Expand All @@ -29,7 +29,7 @@
<key>NSCameraUsageDescription</key>
<string>Camera usage for Perse</string>
<key>NSPerseUsageDescription</key>
<string>The face detection&apos;s module for iOS with a lot of awesome features</string>
<string>The face detection's module for iOS with a lot of awesome features</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>This app requires access to the photo library</string>
<key>UIApplicationSceneManifest</key>
Expand Down
23 changes: 13 additions & 10 deletions Example/PerseDemo/PerseDemo/PerseCameraViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@ class PerseCameraViewController:
@IBOutlet var horizontalMovementLabel: UILabel!
@IBOutlet var verticalMovementLabel: UILabel!
@IBOutlet var tiltMovementLabel: UILabel!
@IBOutlet var faceUnderexposeIcon: UIImageView!
@IBOutlet var faceUnderexposureIcon: UIImageView!
@IBOutlet var faceSharpnessIcon: UIImageView!
@IBOutlet var imageUnderexposeIcon: UIImageView!
@IBOutlet var imageUnderexposureIcon: UIImageView!
@IBOutlet var imageSharpnessIcon: UIImageView!
var image: UIImage?

override func viewDidLoad() {
super.viewDidLoad()

self.reset()

self.perseCamera.apiKey = Environment.apiKey

self.perseCamera.perse = Perse(
apiKey: Environment.apiKey,
baseUrl: Environment.baseUrl
)
self.perseCamera.perseEventListener = self
self.perseCamera.startPreview()
self.perseCamera.setDetectionBox(true)
Expand All @@ -37,7 +40,7 @@ class PerseCameraViewController:
_ count: Int,
_ total: Int,
_ imagePath: String,
_ detectResponse: DetectResponse?
_ detectResponse: PerseAPIResponse.Face.Detect?
) {
let subpath = imagePath
.substring(
Expand All @@ -60,12 +63,12 @@ class PerseCameraViewController:
}

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

self.setSpoofingValidation(valid: face.livenessScore >= detectResponse.defaultThresholds.liveness)
self.faceUnderexposeIcon.validate(valid: face.faceMetrics.underexposure > detectResponse.defaultThresholds.underexposure)
self.faceUnderexposureIcon.validate(valid: face.faceMetrics.underexposure > detectResponse.defaultThresholds.underexposure)
self.faceSharpnessIcon.validate(valid: face.faceMetrics.sharpness < detectResponse.defaultThresholds.sharpness)
self.imageUnderexposeIcon.validate(valid: detectResponse.imageMetrics.underexposure > detectResponse.defaultThresholds.underexposure)
self.imageUnderexposureIcon.validate(valid: detectResponse.imageMetrics.underexposure > detectResponse.defaultThresholds.underexposure)
self.imageSharpnessIcon.validate(valid: detectResponse.imageMetrics.sharpness < detectResponse.defaultThresholds.sharpness)
}

Expand Down Expand Up @@ -190,9 +193,9 @@ class PerseCameraViewController:
self.horizontalMovementLabel.text = "-"
self.verticalMovementLabel.text = "-"
self.tiltMovementLabel.text = "-"
self.faceUnderexposeIcon.reset()
self.faceUnderexposureIcon.reset()
self.faceSharpnessIcon.reset()
self.imageUnderexposeIcon.reset()
self.imageUnderexposureIcon.reset()
self.imageSharpnessIcon.reset()
self.perseCamera.setDetectionBoxColor(0, 1, 1, 1)
self.perseCamera.setFaceContoursColor(0, 1, 1, 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class PerseDetectViewController:
detectResponse.totalFaces
))

guard let faces = detectResponse.faces as Array<FaceResponse>? else {
guard let faces = detectResponse.faces as Array<PerseAPIResponse.Face.Face>? else {
return
}

Expand Down
2 changes: 1 addition & 1 deletion Example/PerseDemo/PerseDemoTests/DataUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation
import UIKit

func getTempData(name: String) -> Data? {
guard let fileUrl: URL = Bundle(for: PerseFaceDetectWithDataTests.self)
guard let fileUrl: URL = Bundle(for: FaceDetectWithDataTests.self)
.url(
forResource: name,
withExtension: "jpeg"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,43 @@ import Perse
import PerseLite
import Foundation

class PerseFaceCompareWithDataTests: XCTestCase {
func testWithSameHuman() {
class FaceCompareWithDataTests: XCTestCase {

func test_with_same_human() {
compareWithData(
self,
firstImageName: "human",
secondImageName: "human1",
apiKey: Environment.apiKey
) { response in
XCTAssertEqual(response.status, 200)
XCTAssertGreaterThan(response.similarity, response.defaultThresholds.similarity)
XCTAssertGreaterThan(
response.similarity,
response.defaultThresholds.similarity
)
} onError: { error in
XCTFail("Error on compare: \(error)")
}
}
func testWithDifferentHumans() {

func test_with_different_humans() {
compareWithData(
self,
firstImageName: "human1",
secondImageName: "human2",
apiKey: Environment.apiKey
) { response in
XCTAssertEqual(response.status, 200)
XCTAssertLessThan(response.similarity, response.defaultThresholds.similarity)
XCTAssertLessThan(
response.similarity,
response.defaultThresholds.similarity
)
} onError: { error in
XCTFail("Error on compare: \(error)")
}
}
func testWithHumanAndNonHuman() {

func test_with_human_and_non_human() {
compareWithData(
self,
firstImageName: "human",
Expand All @@ -45,8 +51,8 @@ class PerseFaceCompareWithDataTests: XCTestCase {
XCTAssertEqual(error, "402")
}
}
func testWithNonHumanAndHuman() {

func test_with_non_human_and_human() {
compareWithData(
self,
firstImageName: "dog",
Expand All @@ -58,8 +64,8 @@ class PerseFaceCompareWithDataTests: XCTestCase {
XCTAssertEqual(error, "402")
}
}
func testWithNonHumanAndNonHuman() {

func test_with_non_human_and_non_human() {
compareWithData(
self,
firstImageName: "dog",
Expand All @@ -71,21 +77,8 @@ class PerseFaceCompareWithDataTests: XCTestCase {
XCTAssertEqual(error, "402")
}
}

func testWithAPIKeyInvalid() {
compareWithData(
self,
firstImageName: "human",
secondImageName: "human2",
apiKey: ""
) { detectResponse in
XCTFail("Back-end authorized invalid api token.")
} onError: { error in
XCTAssertEqual(error, "401")
}
}

func testWithImagePathsInvalid() {

func test_with_image_paths_invalid() {
compareWithData(
self,
firstImageName: "test0",
Expand All @@ -94,11 +87,14 @@ class PerseFaceCompareWithDataTests: XCTestCase {
) { detectResponse in
XCTFail("")
} onError: { error in
XCTAssertEqual(error, Perse.Error.INVALID_IMAGE_PATH)
XCTAssertEqual(
error,
PerseLite.Error.INVALID_IMAGE_PATH
)
}
}
func testWithNonHumans() {

func test_with_non_humans() {
compareWithData(
self,
firstImageName: "dog",
Expand All @@ -110,5 +106,5 @@ class PerseFaceCompareWithDataTests: XCTestCase {
XCTAssertEqual(error, "402")
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,43 @@ import Perse
import PerseLite
import Foundation

class PerseFaceCompareWithFileTests: XCTestCase {
func testWithSameHuman() {
class FaceCompareWithFileTests: XCTestCase {

func test_with_same_human() {
compareWithFile(
self,
firstImageName: "human",
secondImageName: "human1",
apiKey: Environment.apiKey
) { response in
XCTAssertEqual(response.status, 200)
XCTAssertGreaterThan(response.similarity, response.defaultThresholds.similarity)
XCTAssertGreaterThan(
response.similarity,
response.defaultThresholds.similarity
)
} onError: { error in
XCTFail("Error on compare: \(error)")
}
}
func testWithDifferentHumans() {

func test_with_different_humans() {
compareWithFile(
self,
firstImageName: "human1",
secondImageName: "human2",
apiKey: Environment.apiKey
) { response in
XCTAssertEqual(response.status, 200)
XCTAssertLessThan(response.similarity, response.defaultThresholds.similarity)
XCTAssertLessThan(
response.similarity,
response.defaultThresholds.similarity
)
} onError: { error in
XCTFail("Error on compare: \(error)")
}
}
func testWithHumanAndNonHuman() {

func test_with_human_and_non_human() {
compareWithFile(
self,
firstImageName: "human",
Expand All @@ -45,8 +51,8 @@ class PerseFaceCompareWithFileTests: XCTestCase {
XCTAssertEqual(error, "402")
}
}
func testWithNonHumanAndHuman() {

func test_with_non_human_and_human() {
compareWithFile(
self,
firstImageName: "dog",
Expand All @@ -58,8 +64,8 @@ class PerseFaceCompareWithFileTests: XCTestCase {
XCTAssertEqual(error, "402")
}
}
func testWithNonHumanAndNonHuman() {

func test_with_non_human_and_non_human() {
compareWithFile(
self,
firstImageName: "dog",
Expand All @@ -71,21 +77,8 @@ class PerseFaceCompareWithFileTests: XCTestCase {
XCTAssertEqual(error, "402")
}
}

func testWithAPIKeyInvalid() {
compareWithFile(
self,
firstImageName: "human",
secondImageName: "human2",
apiKey: ""
) { detectResponse in
XCTFail("Back-end authorized invalid api token.")
} onError: { error in
XCTAssertEqual(error, "401")
}
}

func testWithImagePathsInvalid() {

func test_with_image_paths_invalid() {
compareWithFile(
self,
firstImageName: "test0",
Expand All @@ -94,11 +87,14 @@ class PerseFaceCompareWithFileTests: XCTestCase {
) { detectResponse in
XCTFail("")
} onError: { error in
XCTAssertEqual(error, Perse.Error.INVALID_IMAGE_PATH)
XCTAssertEqual(
error,
PerseLite.Error.INVALID_IMAGE_PATH
)
}
}
func testWithNonHumans() {

func test_with_non_humans() {
compareWithFile(
self,
firstImageName: "dog",
Expand All @@ -110,5 +106,5 @@ class PerseFaceCompareWithFileTests: XCTestCase {
XCTAssertEqual(error, "402")
}
}

}
Loading

0 comments on commit d50b1eb

Please sign in to comment.