人脸识别应用于许多领域。二维码的识别更是疯狂。下面,我们一起去看看简单的人脸识别和二维码识别。

1、测试数据的展示(人脸)。

原图:

1、人脸的大小

// 人脸大小

CGRect FaceRect  = FaceFeature.bounds;

NSLog(@"H:%f  W:%f",FaceRect.size.height,FaceRect.size.width);

// 人脸的位置

NSLog(@"X:%f  Y:%f",FaceRect.origin.x,FaceRect.origin.y);

/*

* 输出信息的校验

* 2016-07-09 17:55:05.210 CIDetector_zsj[1849:136896] H:212.000000  W:212.000000

* 2016-07-09 17:55:05.211 CIDetector_zsj[1849:136896] X:203.000000  Y:419.000000

* 解说:

*     原始图片的大小是 600 * 854 px.

*     图片上人脸的位置 X: 210  px      Y: 420 px     (对于位置的展示,请理解画布的原点在哪里为准?)

*     图片上人脸的大小(正方形算)  213 * 213 px

*     输出人脸信息相比精度还是很高

*/

// *************

// 人的眼睛 (左右)

// 判断人的眼睛在图上是否显示

EyesLeft   IsSave= [FaceFeature hasLeftEyePosition];

if (IsSave) {

// 人左眼的位置

CGPoint EyesLeftCGPoint  = FaceFeature.leftEyePosition;

NSLog(@"EyeLeft_X:%f  EyesLeft_Y:%f",EyesLeftCGPoint.x,EyesLeftCGPoint.y);

/*

*   输出数据: 2016-07-09 18:42:20.295 CIDetector_zsj[2156:155810]

EyeLeft_X:284.000000  EyesLeft_Y:584.000000

*

*   实际图片上的左眼位置:

EyeLeft_X:284.000000  EyesLeft_Y:587.000000

*

*   两组数据进行对比,几乎一样,精度很高。

*/

// 左眼是否是关闭的

EyesLeft CloseEyesLeft = FaceFeature.leftEyeClosed;

if (CloseEyesLeft) {

NSLog(@"左眼是闭上的");

}else{

NSLog(@"左眼是睁开的");

}

/*

*  输出信息:

2016-07-09 18:48:40.408 CIDetector_zsj[2241:159731] 左眼是睁开的    (符合实际)

*/

}

// *******************

// 人的右眼

EyesRight IsSaveR = FaceFeature.hasRightEyePosition;

if (IsSaveR) {

// 获取人眼右眼的位置

CGPoint EyesRightCGPoint = FaceFeature.rightEyePosition;

NSLog(@"EyesRight_X:%f   EyesRight_Y:%f",EyesRightCGPoint.x,EyesRightCGPoint.y);

/*

* 输出右眼位置信息:

2016-07-09 19:07:45.125 CIDetector_zsj[2335:164771]

EyesRight_X:368.000000   EyesRight_Y:565.000000

*

* 实际的右眼的位置:

EyesRight_X:367.000000   EyesRight_Y:565.000000

*

* 数据比较接近,精度很高

*/

// 检测人都眼睛是否是闭上的

EyesRight CloseEyesRight = FaceFeature.rightEyeClosed;

if (CloseEyesRight) {

NSLog(@"右眼是闭上的");

}else{

NSLog(@"右眼是睁开的");

}

/*

* 输出信息:

2016-07-09 19:12:38.295 CIDetector_zsj[2387:167289] 右眼是睁开的 (符合实际)

*/

}

// ***********************

// 人的嘴

// 判断人的嘴是否在图片上

Mouth  MouthIsSave = FaceFeature.hasMouthPosition;

if (MouthIsSave) {

CGPoint MouthCgPoint = FaceFeature.mouthPosition;

NSLog(@"Mouth_X:%f   Mouth_Y:%f",MouthCgPoint.x,MouthCgPoint.y);

/**

*  输出信息:

2016-07-09 19:19:22.408 CIDetector_zsj[2474:171661]

Mouth_X:298.000000   Mouth_Y:474.000000

*

*  实际嘴的位置:

Mouth_X:301.000000   Mouth_Y:474.000000

*

*  数据分析的结果两组数据几乎一样,精度很高

*/

// 判断人脸是否微笑

Mouth IsSmile = FaceFeature.hasSmile;

if (IsSmile) {

NSLog(@"人在微笑");

}else{

NSLog(@"人不在微笑");

}

/*

*  输出信息:

2016-07-09 19:27:22.460 CIDetector_zsj[2561:175632] 人不在微笑  (符合实际)

*/

}

// ****************

// 获取人脸的角度

BOOL FaceAngle = FaceFeature.hasFaceAngle;

if (FaceAngle) {

float Angle = FaceFeature.faceAngle;

NSLog(@"FaceAngle:%f",Angle);

/*

* 输出的信息

* 2016-07-09 19:32:42.485 CIDetector_zsj[2638:178512] FaceAngle:13.000000

*

* 解说:以中为 0 度  ,向左为正 (0~90)度 ,向右为(0~90)度

*/

}

// 获取追踪对象

BOOL  Istracking = FaceFeature.hasTrackingID;

if (Istracking) {

// 获取追踪的对象的ID

int TrackingID = FaceFeature.trackingID;

NSLog(@"Tracking:%d",TrackingID);

}

}

2、二维码识别。

// 获取图像的大小

CGRect QRCodeRect = QRCodeFeature.bounds;

NSLog(@"W:%f   H:%f",QRCodeRect.size.width,QRCodeRect.size.height);

// 二维码的内容

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

UIAlertController * QRCodeAlert = [UIAlertController alertControllerWithTitle:@"二维码识别" message:QRCodeFeature.messageString preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction * Action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

}];

[QRCodeAlert addAction:Action];

[self presentViewController:QRCodeAlert animated:YES completion:nil];

});

3、完整代码。

//

//  ViewController.m

//  CIDetector_zsj

//

//  Created by 周双建 on 16/7/9.

//  Copyright © 2016年 周双建. All rights reserved.

//

#import "ViewController.h"

// 引入探测启的头文件

#import <CoreImage/CIDetector.h>

typedef NSDictionary Performance ;

typedef NSArray DetectionDataArray;

typedef BOOL EyesLeft;

typedef BOOL EyesRight;

typedef BOOL Mouth;

typedef NSArray QRCodeArray;

typedef NSArray ContentArray;

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

// 创建探测器的对象 唯一的方法

/**

*

* @type 有四种类型 如下:

* 范围系统限制: MAC OSX 10_7 以上 ;  IOS SDK_5.0 以上

*

* CIDetectorTypeFace 是用于人脸识别的类型

*

* CIDetectorTypeRectangle 是用于识别大小的类型

*

* CIDetectorTypeQRCode   是用于条形码&二维码识别的类型

*

*@ context 是用于对图像进行操作的

*

*@ options 是一个字典  用于设置探测器的性能

*/

/**

* CIDetectorAccuracy(精度)  &&  CIDetectorTracking(轨迹)对与探测器的精度有两个字 key

*

* CIDetectorAccuracyHigh(高) &&  CIDetectorAccuracyLow(低)  Value

*

*/

/**********∑∑人脸识别*****************************/

// 我们准备要识别的人脸 (美女一个)

// 正要说明: 经过测试,侧脸检测不到。

// 创建人脸对象 (有好多中创建方法,可根据自己需求选择)

CIImage *FaceCImage = [CIImage imageWithData:UIImagePNGRepresentation([UIImage imageNamed:@"right1.jpg"])];

// 设置探测器的性能

Performance  * FaceDetectorDict = @{@"CIDetectorAccuracy":@"CIDetectorAccuracyHigh",@"CIDetectorTracking":@"1"};

// 创建探测器的对象

CIDetector * FaceDetector = [CIDetector detectorOfType:CIDetectorTypeFace context:nil options:FaceDetectorDict];

// 获取探测到得人脸信息

DetectionDataArray * FaceArray = [FaceDetector featuresInImage:FaceCImage options:FaceDetectorDict];

// 获取人脸的个部位的信息

for (CIFaceFeature * FaceFeature in FaceArray) {

// ************

// 人脸大小

CGRect FaceRect  = FaceFeature.bounds;

NSLog(@"H:%f  W:%f",FaceRect.size.height,FaceRect.size.width);

// 人脸的位置

NSLog(@"X:%f  Y:%f",FaceRect.origin.x,FaceRect.origin.y);

/*

* 输出信息的校验

* 2016-07-09 17:55:05.210 CIDetector_zsj[1849:136896] H:212.000000  W:212.000000

* 2016-07-09 17:55:05.211 CIDetector_zsj[1849:136896] X:203.000000  Y:419.000000

* 解说:

*     原始图片的大小是 600 * 854 px.

*     图片上人脸的位置 X: 210  px      Y: 420 px     (对于位置的展示,请理解画布的原点在哪里为准?)

*     图片上人脸的大小(正方形算)  213 * 213 px

*     输出人脸信息相比精度还是很高

*/

// *************

// 人的眼睛 (左右)

// 判断人的眼睛在图上是否显示

EyesLeft   IsSave= [FaceFeature hasLeftEyePosition];

if (IsSave) {

// 人左眼的位置

CGPoint EyesLeftCGPoint  = FaceFeature.leftEyePosition;

NSLog(@"EyeLeft_X:%f  EyesLeft_Y:%f",EyesLeftCGPoint.x,EyesLeftCGPoint.y);

/*

*   输出数据: 2016-07-09 18:42:20.295 CIDetector_zsj[2156:155810]

EyeLeft_X:284.000000  EyesLeft_Y:584.000000

*

*   实际图片上的左眼位置:

EyeLeft_X:284.000000  EyesLeft_Y:587.000000

*

*   两组数据进行对比,几乎一样,精度很高。

*/

// 左眼是否是关闭的

EyesLeft CloseEyesLeft = FaceFeature.leftEyeClosed;

if (CloseEyesLeft) {

NSLog(@"左眼是闭上的");

}else{

NSLog(@"左眼是睁开的");

}

/*

*  输出信息:

2016-07-09 18:48:40.408 CIDetector_zsj[2241:159731] 左眼是睁开的    (符合实际)

*/

}

// *******************

// 人的右眼

EyesRight IsSaveR = FaceFeature.hasRightEyePosition;

if (IsSaveR) {

// 获取人眼右眼的位置

CGPoint EyesRightCGPoint = FaceFeature.rightEyePosition;

NSLog(@"EyesRight_X:%f   EyesRight_Y:%f",EyesRightCGPoint.x,EyesRightCGPoint.y);

/*

* 输出右眼位置信息:

2016-07-09 19:07:45.125 CIDetector_zsj[2335:164771]

EyesRight_X:368.000000   EyesRight_Y:565.000000

*

* 实际的右眼的位置:

EyesRight_X:367.000000   EyesRight_Y:565.000000

*

* 数据比较接近,精度很高

*/

// 检测人都眼睛是否是闭上的

EyesRight CloseEyesRight = FaceFeature.rightEyeClosed;

if (CloseEyesRight) {

NSLog(@"右眼是闭上的");

}else{

NSLog(@"右眼是睁开的");

}

/*

* 输出信息:

2016-07-09 19:12:38.295 CIDetector_zsj[2387:167289] 右眼是睁开的 (符合实际)

*/

}

// ***********************

// 人的嘴

// 判断人的嘴是否在图片上

Mouth  MouthIsSave = FaceFeature.hasMouthPosition;

if (MouthIsSave) {

CGPoint MouthCgPoint = FaceFeature.mouthPosition;

NSLog(@"Mouth_X:%f   Mouth_Y:%f",MouthCgPoint.x,MouthCgPoint.y);

/**

*  输出信息:

2016-07-09 19:19:22.408 CIDetector_zsj[2474:171661]

Mouth_X:298.000000   Mouth_Y:474.000000

*

*  实际嘴的位置:

Mouth_X:301.000000   Mouth_Y:474.000000

*

*  数据分析的结果两组数据几乎一样,精度很高

*/

// 判断人脸是否微笑

Mouth IsSmile = FaceFeature.hasSmile;

if (IsSmile) {

NSLog(@"人在微笑");

}else{

NSLog(@"人不在微笑");

}

/*

*  输出信息:

2016-07-09 19:27:22.460 CIDetector_zsj[2561:175632] 人不在微笑  (符合实际)

*/

}

// ****************

// 获取人脸的角度

BOOL FaceAngle = FaceFeature.hasFaceAngle;

if (FaceAngle) {

float Angle = FaceFeature.faceAngle;

NSLog(@"FaceAngle:%f",Angle);

/*

* 输出的信息

* 2016-07-09 19:32:42.485 CIDetector_zsj[2638:178512] FaceAngle:13.000000

*

* 解说:以中为 0 度  ,向左为正 (0~90)度 ,向右为(0~90)度

*/

}

// 获取追踪对象

BOOL  Istracking = FaceFeature.hasTrackingID;

if (Istracking) {

// 获取追踪的对象的ID

int TrackingID = FaceFeature.trackingID;

NSLog(@"Tracking:%d",TrackingID);

}

}

// **************∑∑∑二维码识别***************************

// 导入识别对象

CIImage  * QRcodeImage = [CIImage imageWithData:UIImagePNGRepresentation([UIImage imageNamed:@"tixingma.png"])];

// 配置探测器的性质

Performance  * QRcodeDetectorDict = @{@"CIDetectorAccuracy":@"CIDetectorAccuracyHigh"};

// 创建探测器

CIDetector  * QRCodeDetector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:nil options:QRcodeDetectorDict];

// 获取图像信息

QRCodeArray * CodeArray = [QRCodeDetector featuresInImage:QRcodeImage];

for (CIQRCodeFeature * QRCodeFeature  in CodeArray) {

// 获取图像的大小

CGRect QRCodeRect = QRCodeFeature.bounds;

NSLog(@"W:%f   H:%f",QRCodeRect.size.width,QRCodeRect.size.height);

// 二维码的内容

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

UIAlertController * QRCodeAlert = [UIAlertController alertControllerWithTitle:@"二维码识别" message:QRCodeFeature.messageString preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction * Action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

}];

[QRCodeAlert addAction:Action];

[self presentViewController:QRCodeAlert animated:YES completion:nil];

});

}

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

@end

IOS人脸识别和二维码识别相关推荐

  1. OPT小讲堂 ∣ SciSmart图像识别之条形码识别、二维码识别

    在第十三课中,我们讲了图像识别中的OCR:字符识别. 本课将继续介绍图像识别中的条形码识别.二维码识别.我们将分别介绍二者的基本概念.操作流程.参数解析及应用案例. 条形码识别 条形码识别的概念 条形 ...

  2. 了解人脸识别和二维码识别

    人脸识别方案 CoreImage (二维码识别,人脸识别) face++ 2014阿里 收费(两种方案本地计算 服务器计算) 腾讯优图 OpenCV (人脸识别 滤镜等) libefacedetect ...

  3. opencv-python 人脸检测,边缘检测,识别形状,图像分割,OCR,OMR,验证码识别,二维码识别,行人检测等应用解决思路

    opencv-python作为经典的计算机视觉,图片处理平台,可以用来开发很多基础应用,关于opencv-python里边函数的应用小结如下,欢迎讨论: 人脸检测 一般用 haarCascade 车牌 ...

  4. Android Zxing识别图片二维码识别率低

    1.使用Zxing对图片进行识别二维码 在gradle中引入识别库: implementation 'com.google.zxing:core:3.4.1' 对Bitmap进行识别二维码: int[ ...

  5. AVFoundation 二维码识别,人脸识别

    二维码识别 AVFoundation 二维码识别demo 主要代码: #import "THCameraController.h" #import <AVFoundation ...

  6. Halcon一维码和二维码识别

    Halcon一维码和二维码识别 一.Halcon一维码识别 二.Halcon二维码识别 一.Halcon一维码识别 1.一维码的识别过程: (1).创建条码模型create_bar_code_mode ...

  7. K210学习笔记(十)——二维码识别

    前言 MAIX BIT(K210)和openmv在传统视觉处理这个方面代码是通用的,掌握K210的色块识别和二维码识别其实也掌握了openmv对应的用法. 一.二维码是什么? 二维码 (2-dimen ...

  8. python实现二维码识别软件_OpenCV和Zbar两个Python模块实现二维码和条形码识别

    在我们的日常生活中,处处可见条形码和二维码. 在以前,我们去逛书店时,或者你现在随手拿起你身边的一本书,你肯定能看到书本的封页后面印有一排黑色线条组成的标签,也就是条形码:你去你们学校的自助机上借书还 ...

  9. 人脸识别、二维码电子签到,让会议会展入场更加智能!

    签到,是一种识别,辩证,是出入一场活动的凭证,趋于不同类型的活动,不同规模使用的签到方式是不一样的. 在会议会展活动当中,往往第一关就是签到环节,一个巧妙专业的签到安排往往比会议本身更能给参会嘉宾留下 ...

最新文章

  1. 【机器学习】激活函数(Activation Function)
  2. 结构化的网络故障检测与排除方法
  3. Unity3D_NGUI_安卓APK安装包瘦身实践
  4. Spring-jdbc:JdbcTemplate使用简介
  5. python中的seed_Python seed() 函数 - Python 教程 - 自强学堂
  6. 构建第一个fabric网络
  7. HDU 2144 (最长连续公共子列 + 并查集) Evolution
  8. 手机通过USB共享电脑宽带
  9. 【基于HTML技术的趣味“2048”小游戏】(效果+源代码)
  10. 第十四章 涅焚心经的强大之处
  11. 终年32岁的传奇数学家,生前寂寂无闻,一个世纪后却让硅谷领袖们集体落泪致敬
  12. c语言的七大查找算法,非常值得学习
  13. PRML 1.1 多项式曲线拟合
  14. android设备类型,android根据屏幕尺寸区分设备类型,phone或者pad - yuanyuan
  15. 单元测试的艺术--读书笔记
  16. C++对C语言的扩展
  17. php 配置 memcache,php如何配置memcache
  18. 软件开发编码规范_如果您只喜欢编码,请不要成为软件开发人员
  19. 数码摄影色彩管理ABC
  20. 2021/08/01 Terraform 从入门到精通(一)

热门文章

  1. 基于Java+SpringMvc+Vue求职招聘系统详细设计实现
  2. 分享一波关于做Kaggle比赛,Jdata,天池的经验,看完我这篇就够了。
  3. 堆排序 python_堆排序用python
  4. centerOS 7安装MySQL5.7
  5. 北理工嵩天Python语言程序设计笔记(8 文件和数据格式化)
  6. Linux系统日志 -
  7. 大数据监测:肯德基中国正在悄悄涨价
  8. Python实现AES加密算法(无第三方库)
  9. mpc模型预测控制原理详解
  10. java8 对象转map时重复key Duplicate key 该如何解决?