在上篇博客IOS Core Image之一中了解了下CIImage、CIFilter、CIContext三个类的使用,这篇了解下滤镜链(多滤镜)和人脸检测(不是人脸识别)。

一、多滤镜

1.有些效果不只是一个滤镜能完成的,需要多个滤镜叠加,让一个滤镜的outputImage作为另一个滤镜的inputImage。

在下面的代码中,给图片加了两个滤镜效果一个高斯模糊一个旋转。

#import "ViewController.h"
#import <CoreImage/CoreImage.h>
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    CIImage *inputImg = [[CIImage alloc]initWithCGImage:[UIImage imageNamed:@"1.jpg"].CGImage];
    // 滤镜链合成
    CIImage *outputImage = [self oldPhoto:inputImg withAmount:];
    CIContext *context=[CIContext contextWithOptions:nil];
    CGImageRef cgimg =[context createCGImage:outputImage fromRect:[outputImage extent]];
    UIImageView *img = [[UIImageView alloc] initWithFrame:self.view.bounds];
    img.backgroundColor = [UIColor redColor];
    img.contentMode = UIViewContentModeScaleToFill;
    img.image=[UIImage imageWithCGImage:cgimg];
    [self.view addSubview:img];
    CGImageRelease(cgimg);

}
-(CIImage *)oldPhoto:(CIImage *)img withAmount:(float)intensity {

    //高斯模糊滤镜
    CIFilter *gaussianBlurFilter = [CIFilter filterWithName:@"CIGaussianBlur"];

    [gaussianBlurFilter setValue:img forKey:@"inputImage"];
    [gaussianBlurFilter setValue: @(intensity) forKey:@"inputRadius"];

    //旋转滤镜
    CIFilter *affineTransformFilter = [CIFilter filterWithName:@"CIAffineTransform"];
    [affineTransformFilter setValue:gaussianBlurFilter.outputImage forKey:@"inputImage"];
    [affineTransformFilter setValue: [NSValue valueWithCGAffineTransform:CGAffineTransformMakeRotation(intensity)] forKey:@"inputTransform"];
    return affineTransformFilter.outputImage;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

2.效果图

二、人脸检测

1.网上有的写的是人脸识别,了解了下发现CoreImage中的算不上人脸识别,也只是检测下人脸的位置,眼睛、嘴巴、是否微笑等,并不能识别出是不是同一个人。这个参考了博客http://blog.csdn.net/wildfireli/article/details/7164628.用自己素颜图(儿童不宜,戴墨镜观看防止亮瞎眼)试了下还算OK。

//
//  ViewController.m
//  CoreImage
//
//  Created by City--Online on 15/11/10.
//  Copyright © 2015年 City--Online. All rights reserved.
//

#import "ViewController.h"
#import <CoreImage/CoreImage.h>
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIImage* image = [UIImage imageNamed:@"psu.jpg"];
    UIImageView *testImage = [[UIImageView alloc] initWithImage: image];
    [testImage setTransform:CGAffineTransformMakeScale(, -)];
    [[[UIApplication sharedApplication] delegate].window setTransform:
     CGAffineTransformMakeScale(, -)];

    [testImage setFrame:CGRectMake(, , testImage.image.size.width,
                                   testImage.image.size.height)];
    [self.view addSubview:testImage];

    CIImage* ciimage = [CIImage imageWithCGImage:image.CGImage];
//    detectorOfType 检测类型  context画布 options字典
    CIDetector *detector=[CIDetector detectorOfType:CIDetectorTypeFace context:nil options:@{CIDetectorAccuracy:CIDetectorAccuracyHigh}];
    NSArray *features= [detector featuresInImage:ciimage];

    // 在 CIFeature类中有CIFaceFeature、CIRectangleFeature、CIQRCodeFeature、CITextFeature子类
    for (CIFaceFeature *faceFeature in features) {
        CGFloat faceWidth = faceFeature.bounds.size.width;
        if (faceFeature.hasLeftEyePosition) {
            [self addViewWithPoint:faceFeature.leftEyePosition withWidth:faceWidth];
        }
        if (faceFeature.hasRightEyePosition)
        {
            [self addViewWithPoint:faceFeature.rightEyePosition withWidth:faceWidth];
        }
        if (faceFeature.hasMouthPosition) {
            [self addViewWithPoint:faceFeature.mouthPosition withWidth:faceWidth];
        }
    }

}
-(void)addViewWithPoint:(CGPoint)point withWidth:(float)faceWidth
{
    UIView* view = [[UIView alloc] initWithFrame:CGRectMake(point.x-faceWidth*0.1,point.y-faceWidth*0.1, faceWidth*0.2, faceWidth*0.2)];
    [view setBackgroundColor:[[UIColor blueColor] colorWithAlphaComponent:0.3]];
    [view setCenter:point];
    view.layer.cornerRadius = faceWidth*0.1;
    [self.view  addSubview:view];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

2.效果图

由于清屏网无耻,抄袭我博客并将我头像放在它网上,我就把这图去了

三、高斯模糊第三方

项目背景视图要用高斯模糊的效果,在网上找了个第三方UIImage+ImageEffects,东西也不多,效果又很好。

IOS Core Image之二的更多相关文章

  1. iOS开发-定制多样式二维码

    iOS开发-定制多样式二维码   二维码/条形码是按照某种特定的几何图形按一定规律在平台(一维/二维方向上)分布的黑白相间的图形纪录符号信息.使用若干个与二进制对应的几何形体来表示文字数值信息. 最常 ...

  2. View Programming Guide for iOS ---- iOS 视图编程指南(二)---View and Window Architecture

    View and Window Architecture 视图和窗口架构 Views and windows present your application’s user interface and ...

  3. iOS Core Animation 简明系列教程

    iOS Core Animation 简明系列教程  看到无数的CA教程,都非常的难懂,各种事务各种图层关系看的人头大.自己就想用通俗的语言翻译给大家听,尽可能准确表达,如果哪里有问题,请您指出我会尽 ...

  4. iOS使用Zbar扫描二维码

    iOS使用Zbar扫描二维码 标签(空格分隔):二维码扫描 iOS Zbar64位 正文: 首先下载一个支持64位系统的ZbarSDK的包,保存在了我的云盘里,地址:ZbarSDK 把文件拖到工程里面 ...

  5. 转 iOS Core Animation 动画 入门学习(一)基础

    iOS Core Animation 动画 入门学习(一)基础 reference:https://developer.apple.com/library/ios/documentation/Coco ...

  6. IOS开发-文件管理(二)

    IOS开发-文件管理(二) 五.Plist文件 String方式添加               NSString *path = [NSHomeDirectory( )  stringByAppen ...

  7. iOS原生CIFilter创建二维码

    iOS原生CIFilter创建二维码 2016-05-31 未来C iOS原生CIFilter创建二维码 关于二维码生成,网上也是有很多,很早以前的第三方库大多数都是通过C++写,也是有的如zxing ...

  8. iOS安全攻防(二十三):Objective-C代码混淆

    iOS安全攻防(二十三):Objective-C代码混淆 class-dump能够非常方便的导出程序头文件,不仅让攻击者了解了程序结构方便逆向,还让着急赶进度时写出的欠完好的程序给同行留下笑柄. 所以 ...

  9. iOS - Core Animation 核心动画

    1.UIView 动画 具体讲解见 iOS - UIView 动画 2.UIImageView 动画 具体讲解见 iOS - UIImageView 动画 3.CADisplayLink 定时器 具体 ...

随机推荐

  1. 微信小程序web-view之wx.miniProgram.redirectTo

    17年微信小程序官方提供了web-view组件. 官方描述:web-view组件是一个可以用来承载网页的容器,会自动铺满整个小程序页面.个人类型与海外类型的小程序暂不支持使用. 这段时间研究了一下小程 ...

  2. 基于ASP.NET MVC 利用(Aspose+Pdfobject.js) 实现在线预览Word、Excel、PPT、PDF文件

    #region VS2010版本以及以上版本源码下载地址:http://download.csdn.net/download/u012949335/10231812 VS2012版本以及以上版本源码下 ...

  3. 九,php中上传文件

    1,php网页上传文件大小有限制的,默认最大2M.可以修改php.ini调节大小,upload_max_filesize = 2M.网页上传使用http协议,上传大文件性能不好:有些公司做一个客户端软 ...

  4. tf入门-卷积步长strides参数的具体解释

    conv1 = tf.nn.conv2d(input_tensor,conv1_weights,strides=[1,1,1,1],padding='SAME') 这是一个常见的卷积操作,其中stri ...

  5. python 第一天学习(画个正方体)

    import turtleturtle.goto(200,0)turtle.goto(200,200)turtle.goto(0,200)turtle.goto(0,0)turtle.penup()t ...

  6. 聊聊Postgres中的IPC之SI Message Queue

    在 PostgreSQL中,每一个进程都有属于自己的共享缓存(shared cache).例如,同一个系统表在不同的进程中都有对应的Cache来缓存它的元组(对于RelCache来说缓存的是一个Rel ...

  7. 创建第一个flask项目

    安装flask模块 pip install flask或conda install flask 创建一个run.py文件,文件内容如下: from flask import Flask app = F ...

  8. python 异步IO(syncio) 协程

    python asyncio 网络模型有很多中,为了实现高并发也有很多方案,多线程,多进程.无论多线程和多进程,IO的调度更多取决于系统,而协程的方式,调度来自用户,用户可以在函数中yield一个状态 ...

  9. 【性能测试】:oracle数据库的监控方式

    一,[前提]:登陆操作系统后,需要切换到SQLPLUS的命令行模式:sqlplus / as sysdba 二,[监控步骤]:开始时执行一次:SQL>exec DBMS_WORKLOAD_REP ...

  10. Q143 重排链表

    给定一个单链表 L:L0→L1→-→Ln-1→Ln , 将其重新排列后变为: L0→Ln→L1→Ln-1→L2→Ln-2→- 你不能只是单纯的改变节点内部的值,而是需要实际的进行节点交换. 示例 1: ...