• CoreImage 的人脸检测


    CoreImage 可以分析图片并从中找到人脸。但是人脸检测并不能代表人脸识别,人脸识别是指识别出特定的某个人的脸。CoreImge检测到人脸以后,它可以提供一些人脸特征的信息:如眼睛的位置,嘴的位置等。

    知道了人脸的位置,你就可以基于人脸做其他的操作,比如调整人脸部分的图像尺寸,在人脸处加马赛克,或者添加装饰物。

     1 CIContext *context = [CIContext contextWithOptions:nil];  //1
     2     
     3     UIImage *myImage = [UIImage imageNamed:@"aa11.jpg"];
     4     CIImage *image = [CIImage imageWithCGImage:[UIImage imageNamed:@"aa11.jpg"].CGImage];
     5     
     6     NSDictionary *opts = @{ CIDetectorAccuracy : CIDetectorAccuracyHigh};  //2
     7     
     8     CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeFace context:context options:opts];    //3
     9   //  opts = @{CIDetectorImageOrientation : [[image properties] valueForKey:kCIImagePropertyOrientation]};    //4
    10     
    11     NSArray *features = [detector featuresInImage:image options:nil];   //5
    12     
    13     for(CIFaceFeature *f in features)
    14     {
    15         NSLog(@"origin.x:%f,origin.y:%f,size.x:%f,size.y:%f",f.bounds.origin.x,f.bounds.origin
    16               .y,f.bounds.size.width,f.bounds.size.height);
    17         
    18         if(f.hasLeftEyePosition)
    19         {
    20             NSLog(@"Left eye %g,%g", f.leftEyePosition.x,f.leftEyePosition.y);
    21         }
    22         
    23         if (f.hasRightEyePosition)
    24             NSLog(@"Right eye %g ,%g", f.rightEyePosition.x, f.rightEyePosition.y);
    25         if (f.hasMouthPosition)
    26             NSLog(@"Mouth %g ,%g", f.mouthPosition.x, f.mouthPosition.y);
    27         
    28     }
    29     

    1.创建一个context

    2.创建一个可选的字典来具体说明探测器的精确性。你可以设置为高精度或者低精度。低精度(CIDetectorAccuracyLow)速度快,高精度速度慢但是彻底全面。

    3.创建一个面部探测器。

    4.Sets up an options dictionary for finding faces. It’s important to let Core Image know the image orientation so the detector knows where it can find upright faces. Most of the time you’ll read the image orientation from the image itself, and then provide that value to the options dictionary. 

     5.使用探测器在图片中寻找特征。你提供的图片必须是一个CIImage 对象。CoreImage 返回一个 包含CIFeature 对象的数组。

  • 相关阅读:
    汇编自学链接
    数据库 —— Access 数据库
    OpenGL —— 基础笔记
    VMWare复制虚拟机系统后,模块“Disk”无法启动【转】
    DM设备的创建与管理
    RAID磁盘分区的创建
    文件的压缩、解压缩和打包命令
    磁盘及文件系统管理
    Shell编程中的条件判断(条件测试)
    Linux中vim编辑器的缩进的功能键
  • 原文地址:https://www.cnblogs.com/grq186/p/4602925.html
Copyright © 2020-2023  润新知