- (void)viewDidLoad {
[super viewDidLoad];
UIImage *aImage = [UIImage imageNamed:@"证件照.jpg"];
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 120, 160)];
imageView.center = self.view.center;
imageView.layer.borderWidth = 1.0;
imageView.layer.masksToBounds = YES;
//自适应图片宽高比例
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.image = aImage;
[self.view addSubview:imageView];
CIImage* image = [CIImage imageWithCGImage:aImage.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;
aRect.origin.y = imageView.bounds.size.height - aRect.size.height - aRect.origin.y;//self.bounds.size
UIView *vv = [[UIView alloc]initWithFrame:CGRectMake(aRect.origin.x, aRect.origin.y, aRect.size.width, aRect.size.height)];
[vv setTransform:CGAffineTransformMakeScale(1, -1)];
vv.backgroundColor = [UIColor redColor];
vv.alpha = 0.6;
[imageView addSubview:vv];
}
}
本文介绍了一种在iOS应用中实现人脸检测的方法。通过加载一张证件照片并利用Core Image框架中的CIDetector来识别面部特征,实现了在图片上标记出人脸位置的功能。此过程包括设置UIImageView展示图片、调整其大小及位置,以及使用CIDetector检测面部。
23万+

被折叠的 条评论
为什么被折叠?



