iOS library that detects presentation attacks that use devices with screens.
- Open your project in Xcode
- Select your project in the project navigator
- Click on the Package Dependencies tab
- Click the + button under Packages
- In the search bar enter
https://github.com/AppliedRecognition/Spoof-Device-Detection-Apple.git
- Under Dependency Rule select Up to Next Major Version and enter
1.0.2
- If your project doesn't have a Podfile yet navigate to the project's root folder and enter
pod init
, which will create a Podfile - Open the Podfile and inside your target specification add
pod 'SpoofDeviceDetection/Model', '~> 1.0.2'
- In Terminal enter
pod install
- If you have your project open in Xcode, close it and open the xcworkspace generated by CocoaPods
The project contains two targets: SpoofDeviceDetection and SpoofDeviceDetectionModel. The former target contains the logic to run the ML model inference. The latter target contains the ML model and an extension of the SpoofDeviceDetector
class that adds a failable constructor without any parameters.
If you wish, you can distribute the ML model separately from the SpoofDeviceDetection target. The benefit of this is that your app is smaller to install. You will still need the model to make use of the spoof device detector but you can do this separately from the app install.
All Ver-ID liveness detection modules conform to the SpoofDetector protocol of the Liveness Detection library.
import SpoofDeviceDetection
import SpoofDeviceDetectionModel
func detectSpoofInImage(_ image: UIImage, confidenceThreshold: Float = 0.5) async throws -> Bool
let faceRect: CGRect? = detectFaceInImage(image)
let spoofDetector = try SpoofDeviceDetector()
spoofDetector.confidenceThreshold = confidenceThreshold
let isSpoof = try await spoofdetector.isSpoofedImage(image, regionOfInterest: faceRect)
return isSpoof
}
func detectFaceInImage(_ image: UIImage) -> CGRect? {
// TODO: Detect a face in the image
return nil
}
import SpoofDeviceDetection
import SpoofDeviceDetectionModel
func detectSpoofDevicesInImage(_ image: UIImage, confidenceThreshold: Float = 0.5) async throws -> [DetectedSpoof] {
let spoofDetector = try SpoofDeviceDetector()
spoofDetector.confidenceThreshold = confidenceThreshold
let spoofDevices = try await spoofDetector.detectSpoofDevicesInImage(image)
return spoofDevices
}
import SpoofDeviceDetection
func createSpoofDeviceDetector(modelURL: URL) async throws -> SpoofDeviceDetector {
let spoofDetector = try await SpoofDeviceDetector(modelURL: modelURL)
return spoofDetector
}