- Download and Open Project
- Setting Up SDK License Key
iOS-FaceRecognition-FaceLivenessDetection/license.txt
jwIUC3mm7P9uJDPxx/gRUttdS3bDg5n3QFnyySRB/E776MSPQAMubdyFTuzFb7BCdOx4EuoHmcsO
rpeGfI+Z371p/7cInVsnxLZU7PcSJh45Dd7c6maTg0QPwNLDHqdyNzRLFwKXXOX/IVuQNh6Dsen1
mwk6RGQZfReSUU6nLvWzC5sPgYhBVemExbbIa3UdDbBC+Bm4qNeXQ2i/08s9GFrhhbuvdYyI5TGl
6aVFjSGoHQhm/ENI1916+ck7BiguXMA1KFRTlchSWKhyb9CllHOGTomkoBUD3ykLlMGkcuZE8wT6
qpaHrtnmz1TgkP3tjK7L61BaEpWNib3uH29hWA==
override func viewDidLoad() {
super.viewDidLoad()
var ret = SDK_LICENSE_KEY_ERROR.rawValue
if let filePath = Bundle.main.path(forResource: "license", ofType: "txt") {
do {
let license = try String(contentsOfFile: filePath, encoding: .utf8)
ret = FaceSDK.setActivation(license)
} catch {
print("Error reading file: \(error)")
}
} else {
print("File not found")
}
if(ret == SDK_SUCCESS.rawValue) {
ret = FaceSDK.initSDK()
}
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
guard let pixelBuffer: CVPixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return }
CVPixelBufferLockBaseAddress(pixelBuffer, CVPixelBufferLockFlags.readOnly)
let ciImage = CIImage(cvPixelBuffer: pixelBuffer)
let context = CIContext()
let cgImage = context.createCGImage(ciImage, from: ciImage.extent)
let image = UIImage(cgImage: cgImage!)
CVPixelBufferUnlockBaseAddress(pixelBuffer, CVPixelBufferLockFlags.readOnly)
// Rotate and flip the image
var capturedImage = image.rotate(radians: .pi/2)
if(cameraLens_val == .front) {
capturedImage = capturedImage.flipHorizontally()
}
let faceBoxes = FaceSDK.faceDetection(capturedImage)
let faceBox = faceBoxes[0] as! FaceBox
if(faceBox.liveness > livenessThreshold) {
let templates = FaceSDK.templateExtraction(capturedImage, faceBox: faceBox)
...
let similarity = FaceSDK.similarityCalculation(templates, templates2: personTemplates)