@property (strong,nonatomic)UIImage *ima;
@property (strong,nonatomic)UIImageView *iamgeView;
self.ima= [UIImage imageNamed:@"123.png"];
self.iamgeView = [[UIImageView alloc]initWithImage:self.ima];
self.iamgeView.frame = CGRectMake(0, 0, self.ima.size.width, self.ima.size.height);
[self.view addSubview:self.iamgeView];
CIImage *image = [CIImage imageWithCGImage: self.ima.CGImage];
NSDictionary *opts = [NSDictionary dictionaryWithObject:CIDetectorAccuracyHigh forKey: CIDetectorAccuracy];
CIDetector* detector = [CIDetector detectorOfType:CIDetectorTypeFace context:nil options:opts];
//得到面部数据
NSArray* features = [detector featuresInImage:image];
for (CIFaceFeature *f in features)
{
CGRect aRect = f.bounds;
NSLog(@"%f, %f, %f, %f", aRect.origin.x, aRect.origin.y, aRect.size.width, aRect.size.height);
//眼睛和嘴的位置
if(f.hasLeftEyePosition) {
NSLog(@"Left eye %g %g\n", f.leftEyePosition.x, f.leftEyePosition.y);
//添加一个标记
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(f.leftEyePosition.x, self.ima.size.height-f.leftEyePosition.y, 5, 5)];
label.text = @"眼";
label.textColor = [UIColor redColor];
[self.iamgeView addSubview:label];
}
if(f.hasRightEyePosition) {
NSLog(@"Right eye %g %g\n", f.rightEyePosition.x, f.rightEyePosition.y);
//添加一个标记
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(f.rightEyePosition.x, self.ima.size.height-f.rightEyePosition.y, 5, 5)];
label.text = @"眼";
label.textColor = [UIColor redColor];
[self.iamgeView addSubview:label];
}
if(f.hasMouthPosition)
{
NSLog(@"Mouth %g %g\n", f.mouthPosition.x, f.mouthPosition.y);
//添加一个标记
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(f.mouthPosition.x, self.ima.size.height-f.mouthPosition.y, 5, 5)];
label.text = @"嘴";
label.textColor = [UIColor redColor];
[self.iamgeView addSubview:label];
}
if (f.hasSmile) {
NSLog(@"笑了");
}
if (f.hasFaceAngle) {
NSLog(@"FaceAngle %f ", f.faceAngle );
}
}