当前位置:   article > 正文

iOS图像处理——人脸识别_ios 人臉識別

ios 人臉識別

主要用于身份识别。

人脸识别开发

人脸识别过程一般分为3个步骤:

  1. 建立人脸的面纹数据库;
  2. 获取单签人脸面像图片;
  3. 进行比对;

面纹编码可靠性强,可以精确地辨认出某个人。

iOS5之后,通过CIDetector可以获取眼睛和嘴的特征信息,但是并不包括面纹编码提取。

CIDetector能做的是找到一张图片中的人脸,但是这张脸是谁的,无法判断。

之前可以用OpenCV和Face.com来实现。

实例:是猩猩还是小女孩

  1. - (IBAction)detexct:(id)sender {
  2. CIContext *context = [CIContext contextWithOptions:nil];
  3. UIImage *imageInput = [_inputImageView image];
  4. CIImage *image = [CIImage imageWithCGImage:imageInput.CGImage];
  5. //设置识别参数
  6. NSDictionary *param = @{CIDetectorAccuracy : CIDetectorAccuracyHigh};
  7. //声明一个CIDetecor,并设定识别类型
  8. CIDetector *faceDetector = [CIDetector detectorOfType:CIDetectorTypeFace context:context options:param];
  9. //取得识别结果
  10. NSArray *detectResult = [faceDetector featuresInImage:image];
  11. UIView *resultView = [[UIView alloc] initWithFrame:_inputImageView.frame];
  12. [self.view addSubview:resultView];
  13. [detectResult enumerateObjectsUsingBlock:^(CIFaceFeature *faceFeature, NSUInteger idx, BOOL * _Nonnull stop)
  14. {
  15. //脸部
  16. UIView *faceView = [[UIView alloc] initWithFrame:faceFeature.bounds];
  17. faceView.layer.borderWidth = 1;
  18. faceView.layer.borderColor = [UIColor orangeColor].CGColor;
  19. [resultView addSubview:faceView];
  20. //左眼
  21. if (faceFeature.hasLeftEyePosition)
  22. {
  23. UIView *leftEyeView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 5)];
  24. [leftEyeView setCenter:faceFeature.leftEyePosition];
  25. leftEyeView.layer.borderWidth = 1;
  26. leftEyeView.layer.borderColor = [UIColor redColor].CGColor;
  27. [resultView addSubview:leftEyeView];
  28. }
  29. //嘴巴
  30. if (faceFeature.hasMouthPosition)
  31. {
  32. UIView *mouthView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 5)];
  33. [mouthView setCenter:faceFeature.mouthPosition];
  34. mouthView.layer.borderWidth = 1;
  35. mouthView.layer.borderColor = [UIColor redColor].CGColor;
  36. [resultView addSubview:mouthView];
  37. }
  38. }];
  39. [resultView setTransform:CGAffineTransformMakeScale(1, -1)];
  40. if (detectResult.count > 0)
  41. {
  42. CIImage *faceImage = [image imageByCroppingToRect:[detectResult[0] bounds]];
  43. UIImage *face = [UIImage imageWithCGImage:[context createCGImage:faceImage fromRect:faceImage.extent]];
  44. _outputImageView.image = face;
  45. }
  46. }

 

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号