This project demonstrates the integration and usage of PerchEye Framework for face recognition and comparison in iOS applications.
- iOS 14.0+
- Xcode 12.0+
- Swift 5.0+
- Download PerchEye Framework from the official source
- Drag
PerchEyeFramework.xcframeworkinto your Xcode project - Ensure the framework is added to
Frameworks, Libraries, and Embedded Content - Set
Embed & Signfor the framework
Add photo library access permission to Info.plist:
<key>NSPhotoLibraryUsageDescription</key>
<string>App needs access to photos for face analysis</string>import PerchEyeFrameworkclass FacesAnalyzer {
private let perchEye: PerchEyeSwift
init() {
perchEye = PerchEyeSwift()
}
}func analyzeFaces(in firstImages: [UIImage], and secondImages: [UIImage]) async throws -> Float {
return try await withCheckedThrowingContinuation { continuation in
do {
// Open transaction for first image group
perchEye.openTransaction()
let firstHash = try generateHash(for: firstImages)
// Open transaction for second image group
perchEye.openTransaction()
try loadImages(for: secondImages)
// Compare images
let similarity = perchEye.verify(hash: firstHash)
continuation.resume(returning: similarity)
} catch {
continuation.resume(throwing: error)
}
}
}func compareImages() async {
do {
let score = try await facesAnalyzer.analyzeFaces(in: firstImages, and: secondImages)
// Compare with similarity threshold
let threshold: Float = 0.8
if score > threshold {
print("Faces are similar: \(score)")
} else {
print("Faces are different: \(score)")
}
} catch {
print("Analysis error: \(error)")
}
}Main class for working with PerchEye SDK:
analyzeFaces()- compare two groups of imagesgenerateHash()- generate hash for imagesloadImages()- load images for analysis
struct CustomError: Error, LocalizedError, Identifiable {
let id = UUID()
let title: String
let message: String
}Common errors:
sdkNotInitialized- SDK not initializedfaceNotFound- Face not found in imagetransactionNotOpened- Transaction not openedinternalError- Internal SDK error
Component for photo selection:
PhotoFolderView(
images: $viewModel.firstImagesGroup,
selectedItems: $firstSelectedItems,
isPresented: $showFirstPhotoPicker
)Text(String(format: "%.2f", score))
.foregroundColor(score > threshold ? .green : .red)struct ContentView: View {
@StateObject var viewModel = ViewModel()
var body: some View {
VStack {
// Photo selection UI
HStack {
PhotoFolderView(images: $viewModel.firstImagesGroup, ...)
PhotoFolderView(images: $viewModel.secondImagesGroup, ...)
}
// Compare button
Button("Compare Photos") {
Task {
await viewModel.compareImages()
}
}
// Result display
if let score = viewModel.similarityScore {
Text("Similarity: \(String(format: "%.2f", score))")
}
}
.errorAlert($viewModel.error)
}
}- Image Quality: Use images with clearly visible faces
- Lighting: Avoid images with poor lighting conditions
- Face Count: Image should contain only one face
- Similarity Threshold: Recommended threshold of 0.8 for accurate recognition
- Error Handling: Always handle cases when face is not found
Check PerchEye Framework license terms before using in commercial projects.