ios - 如何使用 Depth Api 去除肖像背景?

标签 ios swift core-image cifilter

我正在观看 2017 年的 WWDC 深度图像编辑视频 ( link ),其中他们将肖像模式的背景设为黑色。他们还展示了一些代码,但我不确定如何使用它。谁能提供一些示例代码吗?

黑色背景的肖像图像: enter image description here 代码: enter image description here

最佳答案

我相信你想做的是改变:

vec4 result = vec4(imageColor.rgb * scaleFactor, imageColor.a);

至:

if disparity < cutoff {
    vec4 result = vec4(imageColor.rgb, 0);
}

其中 cutoff 是您想要停止显示的视差(深度)。

我一直在使用 AVDepthData,但对过滤器没有经验。

希望有帮助!

关于ios - 如何使用 Depth Api 去除肖像背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47123710/

相关文章:

objective-c - cocoa 将 CIImage 保存为 bmp 文件图像损坏

ios - CoreImage 的内存泄漏

ios - Swift - 使用 SwiftRangeSlider 更新标签

ios - 我怎样才能为 sizeForItemAt 设置一个 Collection View ?

ios - 制作一个 UITableView "sticky to the bottom"

arrays - Swift:数组映射或减少,用索引枚举

ios - Swift:从 NSItemProvider 内部更改 UITextField 值

ios - Swift: TableView 父类(super class)错误

ios - 找不到成员 'CellForItemAtIndexPath'

ios - 以正确的方向保存图像 - Swift & Core Image