赞
踩
主要用于身份识别。
人脸识别开发
人脸识别过程一般分为3个步骤:
面纹编码可靠性强,可以精确地辨认出某个人。
iOS5之后,通过CIDetector可以获取眼睛和嘴的特征信息,但是并不包括面纹编码提取。
CIDetector能做的是找到一张图片中的人脸,但是这张脸是谁的,无法判断。
之前可以用OpenCV和Face.com来实现。
实例:是猩猩还是小女孩
- - (IBAction)detexct:(id)sender {
- CIContext *context = [CIContext contextWithOptions:nil];
-
- UIImage *imageInput = [_inputImageView image];
- CIImage *image = [CIImage imageWithCGImage:imageInput.CGImage];
-
- //设置识别参数
- NSDictionary *param = @{CIDetectorAccuracy : CIDetectorAccuracyHigh};
- //声明一个CIDetecor,并设定识别类型
- CIDetector *faceDetector = [CIDetector detectorOfType:CIDetectorTypeFace context:context options:param];
- //取得识别结果
- NSArray *detectResult = [faceDetector featuresInImage:image];
-
- UIView *resultView = [[UIView alloc] initWithFrame:_inputImageView.frame];
- [self.view addSubview:resultView];
-
- [detectResult enumerateObjectsUsingBlock:^(CIFaceFeature *faceFeature, NSUInteger idx, BOOL * _Nonnull stop)
- {
- //脸部
- UIView *faceView = [[UIView alloc] initWithFrame:faceFeature.bounds];
- faceView.layer.borderWidth = 1;
- faceView.layer.borderColor = [UIColor orangeColor].CGColor;
- [resultView addSubview:faceView];
- //左眼
- if (faceFeature.hasLeftEyePosition)
- {
- UIView *leftEyeView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 5)];
- [leftEyeView setCenter:faceFeature.leftEyePosition];
- leftEyeView.layer.borderWidth = 1;
- leftEyeView.layer.borderColor = [UIColor redColor].CGColor;
- [resultView addSubview:leftEyeView];
- }
- //嘴巴
- if (faceFeature.hasMouthPosition)
- {
- UIView *mouthView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 5)];
- [mouthView setCenter:faceFeature.mouthPosition];
- mouthView.layer.borderWidth = 1;
- mouthView.layer.borderColor = [UIColor redColor].CGColor;
- [resultView addSubview:mouthView];
- }
- }];
-
- [resultView setTransform:CGAffineTransformMakeScale(1, -1)];
-
- if (detectResult.count > 0)
- {
- CIImage *faceImage = [image imageByCroppingToRect:[detectResult[0] bounds]];
- UIImage *face = [UIImage imageWithCGImage:[context createCGImage:faceImage fromRect:faceImage.extent]];
-
- _outputImageView.image = face;
- }
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。