Image Editing with Depth

Loading Depth Data

首先要获取深度数据到内存

* PHContentEditingInput
* PHImageManager

[asset requestContentEditingInputWithOptions:options completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
        // Create a CIImage from the full image representation.
        NSURL *url = [contentEditingInput fullSizeImageURL];

Testing for Depth Data with ImageIO

查看是否存在深度数据

//Test
CFURLRef ref = (__bridge CFURLRef)url;
CGImageSourceRef source = CGImageSourceCreateWithURL(ref, nil);
CFDictionaryRef dictRef = CGImageSourceCopyProperties(source, nil);
NSLog(@"========= %@",dictRef);

Reading Depth Data

auxiliary

AVDepthData 
@property   CVPixelBufferRef depthDataMap

use Metal or Core Image to process then get DepthImage.

注意事项 需要做几件事:

  • 深度信息分辨率低 scaling up
    CIEdgePreserveUpsampleFilter 上采样图像信息达到保留边缘的效果
    (所有的使用视差而不是深度信息,官方建议是视差效果会更好一点)
  • 深度值并不是局限在 [0,1]的具体值,视差可能0就是无穷远

Filtering with Depth Data

  • sample background effects (混合遮罩)
    稀释效果/背景白化/马赛克(CI 六边形,运动模糊)
    using Disparity as a mask.
  • Custom Depth Effect
  • Depth Blur Effect (景深)
  • 3D Effect

CIAreaMinMaxRed
CIColorMatrix, 线性过滤器 slope and bias 斜率和偏移
CIColorClamp
CIBlendWithMask

//自定义效果

CIColor Kernel
任何自定义的效果。例如:系统相机人像模式下

//景深效果

CIDepthBlurEffect 
load MainImage and DisparityImage final use this filter with name
1. setValue  focus and rectangle
2. use vision framework to special effect (such face detail),Max is 4 faces,提高速率可以 set  InputScaleFactor = 0.5   

// 3D 效果

实现 true 3D,我们需要使用 Metal.

* Mesh
* Vertex shader
* fragment shader 
* CIImageProcessorKernel

Saving Depth Data

  • 方向 Orientation
  • 裁剪 Crop
  • 旋转 Transform

CoreImage 提供了更方便的接口保存实现。

DepthData 可使用的场景:

  1. Edit
  2. capture
  3. share

参考 WWDC2017