zoukankan      html  css  js  c++  java
  • 利用iOS原生系统进行人脸识别+自定义滤镜(GPUImage)

    人脸识别+滤镜效果(基于GPUImage实现的自定义滤镜)

    最近碰到一个好玩的需求。说要客户端这边判定一下是否有人脸。在有的基础上。对相片做进一步的美化滤镜处理。

    • 首先是人脸的识别判定;
      //将图片对象拿到,转化对应CIImage
        CIImage* ciimage = [CIImage imageWithCGImage:_imageView.image.CGImage];
    //配置人脸识别时候的属性值
        NSDictionary* opts = [NSDictionary dictionaryWithObject:
                              CIDetectorAccuracyHigh forKey:CIDetectorAccuracy];
    //配置识别者
        CIDetector* detector = [CIDetector detectorOfType:CIDetectorTypeFace
                                                  context:nil options:opts];
    //拿到识别到的特性
        NSArray* features = [detector featuresInImage:ciimage];
        if (features.count == 0)
        {
            _HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
            _HUD.mode = MBProgressHUDModeAnnularDeterminate;
            _HUD.label.text = @"未识别到人脸!!请返回重试。";
            dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
                sleep(2.0);
                dispatch_async(dispatch_get_main_queue(), ^{
                    [MBProgressHUD hideHUDForView:self.view animated:YES];
                    [self.navigationController popViewControllerAnimated:YES];
                });
            });
        }
        else
        {
            FiltersViewController *beautyVC = [[FiltersViewController alloc] initWithImage:self.image];
            [self.navigationController pushViewController:beautyVC animated:YES];
        }
    
    • 滤镜的自定义和使用。

    对于GPUImage的封装使用,我这里就不一一赘述。自己看demo一一对应吧。

    demo地址

  • 相关阅读:
    八数码难题 (codevs 1225)题解
    小木棍 (codevs 3498)题解
    sliding windows (poj 2823) 题解
    集合删数 (vijos 1545) 题解
    合并果子 (codevs 1063) 题解
    等价表达式 (codevs 1107)题解
    生理周期 (poj 1006) 题解
    区间 (vijos 1439) 题解
    区间覆盖问题 题解
    种树 (codevs 1653) 题解
  • 原文地址:https://www.cnblogs.com/fuunnyy/p/6753910.html
Copyright © 2011-2022 走看看