iOS 人脸识别功能
来源:互联网 发布:网狐棋牌源码搭建教程 编辑:程序博客网 时间:2024/06/09 20:35
使用 coreimage 可以实现人脸识别功能,并且获取到人脸面部五官的位置。
CIContext *context = [[CIContextalloc]init];
CIImage *ciImage = [CIImageimageWithCGImage:_faceImg.CGImage];
NSDictionary *dic = [NSDictionarydictionaryWithObject:CIDetectorAccuracyforKey:CIDetectorAccuracyHigh];
CIDetector *detector = [CIDetectordetectorOfType:CIDetectorTypeFacecontext:niloptions:dic];
NSArray *array = [detector featuresInImage:ciImage];
// 照片中只有一个人脸的人脸识别
if (array.count ==1) {
for (CIFaceFeature *featurein array) {
NSInteger leftEye_X = feature.leftEyePosition.x;
NSInteger leftEye_Y = feature.leftEyePosition.y;
NSInteger rightEye_X = feature.rightEyePosition.x;
NSInteger rightEye_Y = feature.rightEyePosition.y;
// NSInteger mouth_X = feature.mouthPosition.x;
NSInteger mouth_Y = feature.mouthPosition.y;
// 头为正 左眼高 右眼底 需逆时针旋转
if (leftEye_Y > rightEye_Y && leftEye_Y > mouth_Y && leftEye_X < rightEye_X)
{
CGFloat height = leftEye_Y - rightEye_Y;
CGFloat width = rightEye_X - leftEye_X;
CGFloat rad = atan(height/width);
self.transform =CGAffineTransformMakeRotation(-rad);
}else if (leftEye_Y < rightEye_Y && rightEye_Y > mouth_Y && leftEye_X < rightEye_X)
{
CGFloat height = rightEye_Y - leftEye_Y;
CGFloat width = rightEye_X - leftEye_X;
CGFloat rad = atan(height/width);
self.transform =CGAffineTransformMakeRotation(rad);
}else if (leftEye_X >= rightEye_X && leftEye_Y >= rightEye_Y && mouth_Y > leftEye_Y) {
CGFloat height = leftEye_Y - rightEye_Y;
CGFloat width = leftEye_X - rightEye_X;
CGFloat rad = atan(height/width);
self.transform =CGAffineTransformMakeRotation(-(M_PI-rad));
}else if (leftEye_X >= rightEye_X && rightEye_Y >= leftEye_Y && mouth_Y > leftEye_Y) {
CGFloat height = rightEye_Y - leftEye_Y;
CGFloat width = leftEye_X - rightEye_X;
CGFloat rad = atan(height/width);
self.transform =CGAffineTransformMakeRotation((M_PI - rad));
}else{
self.transform =CGAffineTransformMakeRotation(0);
}
}
// 照片中有多个人脸的人脸识别 给每个人脸打上马赛克
}else if (array.count >1){
CGSize inputImageSize = ciImage.extent.size;
CGAffineTransform transform =CGAffineTransformIdentity;
transform = CGAffineTransformScale(transform,1, -1);
transform = CGAffineTransformTranslate(transform,0, -inputImageSize.height);
- iOS 人脸识别功能
- ios 二维码识别功能
- ios人脸识别
- ios人脸识别
- iOS 人脸识别
- IOS人脸识别
- ios 人脸识别
- IOS人脸识别和二维码识别
- iOS实现人脸识别
- ios 人脸识别 资源
- iOS人脸识别技术
- iOS人脸识别技术
- iOS人脸识别(检测)
- 人脸识别 iOS开发
- iOS 人脸识别(检测)
- iOS人脸识别(检测)
- iOS 照片人脸识别
- iOS 人脸识别Demo
- 极客成长手记(3)——浏览网页
- 从JDK 6升级到JDK 7过程中遇到的一个问题(卸载rpm)
- Linux进程基础
- 1.COM基础概念
- 幻方问题
- iOS 人脸识别功能
- 展开与收起效果
- Redis 1
- 剑指offer——C++面试需要的基础知识
- 山东省第七届省赛L题
- libvirt-virsh参数解析代码解读
- Android中堆unlink利用学习
- Linux堆内存管理深入分析
- View中的getScrollX、getScrollY与getLeft、getRight 以及 MotionEvent中的getX、getY与getRawX、getRawY