赞
踩
- //人脸位置检测,并裁剪包含五官的人脸
- - (UIImage *)detectFace{
- UIImage *resultImage;
- if (self.displayImageView.image) {
- CIImage *cgImage = [[CIImage alloc] initWithImage:self.displayImageView.image];
- CIContext *context = [CIContext contextWithOptions:nil];
- CIDetector *faceDetector = [CIDetector detectorOfType:CIDetectorTypeFace context:context options:@{CIDetectorAccuracy:CIDetectorAccuracyHigh}];
- //检测到的人脸数组
- NSArray *faceArray = [faceDetector featuresInImage:cgImage];
- if (faceArray.count > 0) {
- //检测到人脸时获取最后一次监测到的人脸
- CIFeature *faceFeature = [faceArray lastObject];
- CGRect faceBounds = faceFeature.bounds;
- //cgImage计算的尺寸是像素,需要与空间的尺寸做个计算
- //下面几句是为了获取到额头部位做的处理,如果只需要定位到五官可直接取faceBounds的值
- CGFloat scale = cgImage.extent.size.width/ScreenWidth;
- CGFloat offsetY = fabs(
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。