美文网首页
iOS基于CoreImage的人脸识别

iOS基于CoreImage的人脸识别

作者: 小福8090 | 来源:发表于2016-06-16 15:10 被阅读607次

最近老板提了一个很奇葩的问题,怎么用户的头像不是人像。用户用什么做头像,这关我什么事,脑子里在想这个。突然嘴贱说了句,要不加个人脸识别?然后,然后就多了这个神经的需求。需求很简单,就是检测用户提交的头像是否存在人脸,存在就通过上传,没有就提示重新上传。

因为之前没有接触过,我就懵逼了,各种查资料,第三方的SDK,但是我的需求并不需要那么复杂。

后来才知道iOS的CoreImage已经内建了人脸检测的接口,而且几行代码搞掂,检测不是很准,卡通人物的也可以识别出人脸,本人测试的时候也试过没有检测出人脸的,可能我长得不够帅吧。。。。

第一次写文章,好怕怕,希望不要被喷的太多。

+(BOOL)FaceDetectingWith:(UIImage*)aImage

{

CIImage* image = [CIImageimageWithCGImage:aImage.CGImage];

NSDictionary*optsDict = [NSDictionarydictionaryWithObject:CIDetectorAccuracyHigh

forKey:CIDetectorAccuracy];

CIDetector* detector = [CIDetectordetectorOfType:CIDetectorTypeFace

context:nil

options:optsDict];

NSArray* featuresArray = [detectorfeaturesInImage:image];

if(featuresArray.count>0) {

returnYES;

}

else

{

returnNO;

}

}

相关文章

网友评论

      本文标题:iOS基于CoreImage的人脸识别

      本文链接:https://www.haomeiwen.com/subject/tvumdttx.html