@property (strong,nonatomic)UIImage *ima;
@property (strong,nonatomic)UIImageView *iamgeView;
self.ima= [UIImageimageNamed:@"123.png"];
self.iamgeView = [[UIImageViewalloc]initWithImage:self.ima];
self.iamgeView.frame =CGRectMake(0,0, self.ima.size.width, self.ima.size.height);
[self.viewaddSubview:self.iamgeView];
CIImage *image = [CIImageimageWithCGImage: self.ima.CGImage];
NSDictionary *opts = [NSDictionarydictionaryWithObject:CIDetectorAccuracyHighforKey: CIDetectorAccuracy];
CIDetector* detector = [CIDetectordetectorOfType:CIDetectorTypeFacecontext:niloptions:opts];
//得到面部数据
NSArray* features = [detector featuresInImage:image];
for (CIFaceFeature *fin 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 = [[UILabelalloc]initWithFrame:CGRectMake(f.leftEyePosition.x,self.ima.size.height-f.leftEyePosition.y,5, 5)];
label.text = @"眼";
label.textColor = [UIColorredColor];
[self.iamgeViewaddSubview:label];
}
if(f.hasRightEyePosition) {
NSLog(@"Right eye %g %g\n", f.rightEyePosition.x, f.rightEyePosition.y);
//添加一个标记
UILabel *label = [[UILabelalloc]initWithFrame:CGRectMake(f.rightEyePosition.x,self.ima.size.height-f.rightEyePosition.y,5, 5)];
label.text = @"眼";
label.textColor = [UIColorredColor];
[self.iamgeViewaddSubview:label];
}
if(f.hasMouthPosition)
{
NSLog(@"Mouth %g %g\n", f.mouthPosition.x, f.mouthPosition.y);
//添加一个标记
UILabel *label = [[UILabelalloc]initWithFrame:CGRectMake(f.mouthPosition.x,self.ima.size.height-f.mouthPosition.y,5, 5)];
label.text = @"嘴";
label.textColor = [UIColorredColor];
[self.iamgeViewaddSubview:label];
}
if (f.hasSmile) {
NSLog(@"笑了");
}
if (f.hasFaceAngle) {
NSLog(@"FaceAngle %f ", f.faceAngle );
}
}