我建议去Core Image
and CI探测器 https://developer.apple.com/library/ios/documentation/CoreImage/Reference/CIDetector_Ref/index.html#//apple_ref/occ/cl/CIDetector. https://developer.apple.com/library/ios/documentation/GraphicsImaging/Conceptual/CoreImaging/ci_detect_faces/ci_detect_faces.html https://developer.apple.com/library/ios/documentation/GraphicsImaging/Conceptual/CoreImaging/ci_detect_faces/ci_detect_faces.html它自 iOS 5 起就可用,并且有很棒的文档。
创建人脸检测器示例:
CIContext *context = [CIContext contextWithOptions:nil]; // 1
NSDictionary *opts = @{ CIDetectorAccuracy : CIDetectorAccuracyHigh }; // 2
CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeFace
context:context
options:opts]; // 3
opts = @{ CIDetectorImageOrientation :
[[myImage properties] valueForKey:kCGImagePropertyOrientation] }; // 4
NSArray *features = [detector featuresInImage:myImage options:opts]; // 5
代码的作用如下:
1.- 创建上下文;在此示例中,是 iOS 的上下文。您可以使用处理图像中描述的任何上下文创建函数。)您还可以选择在创建检测器时提供 nil 而不是上下文。)
2.- 创建选项字典来指定检测器的精度。您可以指定低或高精度。低精度(CIDetectorAccuracyLow)速度快;本例中显示的高精度是彻底的,但速度较慢。
3.- 创建面部检测器。您可以创建的唯一类型的检测器是针对人脸的检测器。
4.- 设置用于查找面孔的选项字典。让 Core Image 了解图像方向非常重要,这样检测器就知道在哪里可以找到直立的面部。大多数时候,您将从图像本身读取图像方向,然后将该值提供给选项字典。
5.- 使用检测器查找图像中的特征。您提供的图像必须是 CIImage 对象。 Core Image 返回 CIFeature 对象的数组,每个对象代表图像中的一张脸。
这里有一些开放的项目可以帮助您开始CoreImage
或其他技术如GPUImage
or OpenCV
1 https://github.com/aaronabentheuer/AAFaceDetection https://github.com/aaronabentheuer/AAFaceDetection(CIDetector - Swift)
2 https://github.com/BradLarson/GPUImage https://github.com/BradLarson/GPUImage(目标-C)
3 https://github.com/jeroentrappers/FaceDetectionPOC https://github.com/jeroentrappers/FaceDetectionPOC(Objective-C:它已弃用 iOS9 的代码)
4 https://github.com/kairosinc/Kairos-SDK-iOS https://github.com/kairosinc/Kairos-SDK-iOS(目标-C)
5 https://github.com/macmade/FaceDetect https://github.com/macmade/FaceDetect(OpenCV)