iOS中基于CIDetector的人脸识别
来源:互联网 发布:淘宝创业项目 编辑:程序博客网 时间:2024/05/16 05:43
title: iOS中基于CIDetector的人脸识别
type: categories
date: 2016-11-28 14:10:07
categories: OC
tags: [CIDetector, 人脸识别]
CIDetector是iOS中自带的人脸识别框架,使用起来相对方便。
效果图
本文Demo
https://github.com/zhangzhaopds/CIDetector_demo.git
具体实现
// 人脸识别- (void)detectorFace { // 上下文 CIContext *content = [CIContext contextWithOptions:nil]; /** 1、识别精度 Detector Accuracy key: CIDetectorAccuracy value: CIDetectorAccuracyLow 低精度识别速度快 CIDetectorAccuracyHigh 高精度识别速度慢 */ /** 2、识别类型 Detector Types CIDetectorTypeFace 面部识别 CIDetectorTypeRectangle 矩形识别 CIDetectorTypeQRCode 条码识别 CIDetectorTypeText 文本识别 */ /** 3、 具体特征 Feature Detection CIDetectorImageOrientation 图片方向 CIDetectorEyeBlink 识别眨眼(closed eyes) CIDetectorSmile 笑脸 CIDetectorFocalLength 焦距 CIDetectorAspectRatio 矩形宽高比 CIDetectorReturnSubFeatures 是否检测子特征 */ // 配置识别质量 NSDictionary *param = [NSDictionary dictionaryWithObject:CIDetectorAccuracyHigh forKey:CIDetectorAccuracy]; // 创建人脸识别器 CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeFace context:content options:param]; // 识别图片 CIImage *ciImg = [CIImage imageWithCGImage:_myImageView.image.CGImage]; // 识别特征: 这里添加了眨眼和微笑 // CIDetectorSmile 眼部的识别效果很差,很难识别出来 NSDictionary *featuresParam = @{CIDetectorSmile: [NSNumber numberWithBool:true], CIDetectorEyeBlink: [NSNumber numberWithBool:true]}; // 获取识别结果 NSArray *resultArr = [detector featuresInImage:ciImg options:featuresParam]; UIView *resultView = [[UIView alloc] initWithFrame:_myImageView.frame]; [self.view addSubview:resultView]; for (CIFaceFeature *feature in resultArr) { NSLog(@"微笑:%d", feature.hasSmile); NSLog(@"右眼:%d", feature.rightEyeClosed); NSLog(@"左眼:%d", feature.leftEyeClosed); NSLog(@"脸框:%d", feature.hasFaceAngle); NSLog(@"嘴:%d", feature.hasMouthPosition); /** 关于feature中的position需要注意的是: position是以所要识别图像的原始尺寸为标准; 因此, 如果装载图片的UIImageView的尺寸与图片原始尺寸不一样的话,会出现识别的位置有偏差。 */ UIView *faceView = [[UIView alloc] initWithFrame:feature.bounds]; faceView.layer.borderColor = [UIColor redColor].CGColor; faceView.layer.borderWidth = 1; [resultView addSubview:faceView]; // 坐标系的转换 [resultView setTransform:CGAffineTransformMakeScale(1, -1)]; // 左眼 if (feature.hasLeftEyePosition) { UIView * leftEyeView = [[UIView alloc] initWithFrame:CGRectMake(0, 30, 20, 20)]; [leftEyeView setCenter:feature.leftEyePosition]; leftEyeView.layer.borderWidth = 1; leftEyeView.layer.borderColor = [UIColor greenColor].CGColor; [resultView addSubview:leftEyeView]; } // 右眼 if (feature.hasRightEyePosition) { UIView * rightEyeView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)]; [rightEyeView setCenter:feature.rightEyePosition]; rightEyeView.layer.borderWidth = 1; rightEyeView.layer.borderColor = [UIColor redColor].CGColor; [resultView addSubview:rightEyeView]; } // 嘴部 if (feature.hasMouthPosition) { UIView * mouthView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)]; [mouthView setCenter:feature.mouthPosition]; mouthView.layer.borderWidth = 1; mouthView.layer.borderColor = [UIColor redColor].CGColor; [resultView addSubview:mouthView]; } }}
0 0
- iOS中基于CIDetector的人脸识别
- iOS原生人脸识别CIDetector使用
- Objective-C基于CIDetector的人脸检测
- 利用CIDetector来人脸识别
- iOS中基于OpenCV的人脸识别
- 第五篇 人脸分析CIDetector
- ios学习之基于 OpenCV的人脸识别
- 基于Matlab人脸识别的研究进行中~~
- 基于 HTML5 的人脸识别技术
- 基于 HTML5 的人脸识别技术
- 基于 HTML5 的人脸识别技术
- 基于PCA的人脸识别算法
- 基于pca的人脸识别
- 基于稀疏表示的人脸识别
- 基于PCA的人脸识别步骤
- 基于android的人脸识别
- 基于OpenCV的人脸识别设计方案
- 基于稀疏表示的人脸识别
- C#设计模式-抽象工程模式(6)
- iOS10 UI教程视图的绘制与视图控制器和视图
- 说说Flashback Drop Table缺陷
- Queue操作,该项提交WA,不知原因
- java动态代理(JDK和cglib)
- iOS中基于CIDetector的人脸识别
- 大型情感类电视连续剧--Android高德之旅(1)基础地图
- QT样式的添加方法和box mode
- 博为峰Java技术题 ——JavaEE Servlet 国际化Ⅱ
- java中的注解(Annotation)
- OSX系统添加定时任务
- Android 查看SDK版本
- 处理java日期的一些操作
- JSON