Advertisement
Guest User

Untitled

a guest
Oct 8th, 2015
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. import UIKit
  2. import CoreImage
  3.  
  4. // Unsure why this typealias is needed, but, Swift compiler errors, saying "Use of undeclared type 'CIImage'"
  5. // if we do not typealias CIImage in a func in an extension.
  6. typealias SillyImage = CIImage
  7.  
  8. extension UIImage {
  9. public func isSelfie() -> Bool {
  10. let CIImageRepresentation: SillyImage = self.CIImage ?? SillyImage(image: self)!
  11.  
  12. let context = CIContext(options: nil)
  13. let detectionOptions = [ CIDetectorAccuracy: CIDetectorAccuracyHigh ]
  14. let detector = CIDetector(ofType: CIDetectorTypeFace, context: context, options: detectionOptions)
  15. let features = detector.featuresInImage(CIImageRepresentation)
  16.  
  17. return features.count == 1 && features.first!.type == CIFeatureTypeFace
  18. }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement