使用CoreImage进行人脸识别

来源:互联网 发布:淘宝搜索热词排行榜 编辑:程序博客网 时间:2024/06/05 04:50

[objc] view plaincopy
  1. - (BOOL)checkImageHasFace  
  2. {  
  3.     BOOL hasFace = NO;  
  4.     CIImage *begingImage = [[CIImage alloc] initWithImage:_postImage];  
  5.     //创建CIDetector对象,options使用NSDictionary设置采用高品质还是低品质,这里使用低品质。  
  6.     CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeFace context:nil options:[NSDictionary dictionaryWithObject:CIDetectorAccuracyLow forKey:CIDetectorAccuracy]];  
  7.     //返回数组中包含图片脸部特征信息  
  8.     NSArray *faceFeatures = [detector featuresInImage:begingImage];  
  9.     for (CIFaceFeature *faceFeature in faceFeatures) {  
  10.         //左眼位置、右眼位置和嘴的位置  
  11.         if (faceFeature.hasLeftEyePosition&&faceFeature.hasRightEyePosition&&faceFeature.hasMouthPosition) {  
  12.             hasFace = YES;  
  13.         }  
  14.     }  
  15.     return hasFace;  

0 0