iOS CoreImage之脸部识别
来源:互联网 发布:爱丽丝伪娘团 淘宝 编辑:程序博客网 时间:2024/06/11 15:37
CoreImage一个好玩的地方就是它可以检测出一张人物图片上左眼、右眼以及嘴的详细位置。请注意这里使用的是“检测”而不是“识别”。CoreImage目前还没有办法识别人脸仅仅是检测出人脸的眼嘴位置。
它的使用也是比较方便快捷的。核心代码如下:
UIImage *image = [UIImage imageNamed:@"baby.jpg"]; CIImage *begingImage = [[CIImage alloc] initWithImage:image]; //创建CIDetector对象,options使用NSDictionary设置采用高品质还是低品质,这里使用低品质。 CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeFace context:nil options:[NSDictionary dictionaryWithObject:CIDetectorAccuracyLow forKey:CIDetectorAccuracy]]; //返回数组中包含图片脸部特征信息 NSArray *faceFeatures = [detector featuresInImage:begingImage]; for (CIFaceFeature *faceFeature in faceFeatures) { //脸部宽度 CGFloat faceWidth = faceFeature.bounds.size.width; //左眼的判断 if (faceFeature.hasLeftEyePosition) { UIView *leftEyeView = [[UIView alloc] initWithFrame:CGRectMake(faceFeature.leftEyePosition.x - faceWidth * 0.15, faceFeature.leftEyePosition.y - faceWidth * 0.15, faceWidth * 0.3, faceWidth * 0.3)]; leftEyeView.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.3]; [self.view addSubview:leftEyeView]; } //右眼的判断 if (faceFeature.hasRightEyePosition) { UIView *rightEyeView = [[UIView alloc] initWithFrame:CGRectMake(faceFeature.rightEyePosition.x - faceWidth * 0.15, faceFeature.rightEyePosition.y - faceWidth * 0.15, faceWidth * 0.3, faceWidth * 0.3)]; rightEyeView.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.3]; [self.view addSubview:rightEyeView]; } //嘴的判断 if (faceFeature.hasMouthPosition) { UIView *monthView = [[UIView alloc] initWithFrame:CGRectMake(faceFeature.mouthPosition.x - 0.2 * faceWidth, faceFeature.mouthPosition.y - faceWidth * 0.2, faceWidth * 0.4, faceWidth * 0.4)]; monthView.backgroundColor = [[UIColor greenColor] colorWithAlphaComponent:0.3]; [self.view addSubview:monthView]; } } self.imageView.image = image; [self.imageView sizeToFit]; //旋转 self.imageView.transform = CGAffineTransformMakeScale(1, -1); self.view.transform = CGAffineTransformMakeScale(1, -1);需要注意的是:CIImage的坐标系和UIKit的坐标系是不同的。CIImage的坐标系原点在屏幕的左下角,而UIKit的坐标系原点在屏幕的左上角,所以坐标系需要经过变换。
效果图:
另外就是做了一下卡通人物、动物的图片试验,CoreImage的效果很不错,只有在人物的图片上显示了标记。
- iOS CoreImage之脸部识别
- iOS之使用CoreImage进行人脸识别
- iOS黑科技之(CoreImage)静态人脸识别(一)
- iOS 原生CoreImage人脸识别
- IOS CoreImage实现人脸识别
- 脸部识别
- iOS框架介绍之coreImage
- IOS图像处理之 coreImage.
- IOS图像处理之 coreImage.
- iOS图像处理之 coreImage.
- iOS:CoreImage
- iOS CoreImage
- iOS之CoreImage图像处理框架
- 基于qualcomm平台的kinect教程五之脸部识别
- OpenCV 脸部识别 c++
- 脸部识别SeetaFace介绍
- android指纹识别/脸部识别
- iOS CoreImage学习之高斯模糊效果
- 程序员必看:如何快速戒掉晚睡(熬夜)强迫症
- 利用Windows性能计数器(PerformanceCounter)监控
- 【PreferenceActivity】PreferenceActivity简介
- Ubuntu中,useradd和adduser的区别
- Linux命令模式与编辑模式的切换
- iOS CoreImage之脸部识别
- 只要肯用脑子,就不是简单的重复
- AWK命令详解(大全)
- svnadmin
- Subversion使用心得
- ubuntu下把程序下载到开发板执行
- 使用SharedPreferences读写数据
- 知识与经验积累
- PHP5.5正式版发布,不再支持Windows XP