Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- import CoreImage
- // Unsure why this typealias is needed, but, Swift compiler errors, saying "Use of undeclared type 'CIImage'"
- // if we do not typealias CIImage in a func in an extension.
- typealias SillyImage = CIImage
- extension UIImage {
- public func isSelfie() -> Bool {
- let CIImageRepresentation: SillyImage = self.CIImage ?? SillyImage(image: self)!
- let context = CIContext(options: nil)
- let detectionOptions = [ CIDetectorAccuracy: CIDetectorAccuracyHigh ]
- let detector = CIDetector(ofType: CIDetectorTypeFace, context: context, options: detectionOptions)
- let features = detector.featuresInImage(CIImageRepresentation)
- return features.count == 1 && features.first!.type == CIFeatureTypeFace
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement