【问题标题】:CIDepthBlurEffect Failed to render part of the image because of the memory requirement由于内存需求,CIDepthBlurEffect 无法渲染部分图像
【发布时间】:2019-11-19 20:33:57
【问题描述】:

CIDepthBlurEffect 通常可以在装有 ios 12.4 的手机上运行,​​但是当我尝试检查“inputFocusRect”参数时会出现以下错误?当我设置 y : 0; 时也不会产生错误。但是图像未处理。任何的想法?谢谢。

  • 无法渲染 12192768 像素,因为 CIKernel 的 ROI 函数不允许平铺。
  • 无法渲染部分图像,因为 -1 的内存要求太大。

代码如下:

if let filter = CIFilter(name: "CIDepthBlurEffect", parameters: [kCIInputImageKey : mainImage, kCIInputDisparityImageKey : disparityMap])   {

    filter.setValue(0.1, forKey: "inputAperture")
    filter.setValue(0.1, forKey: "inputScaleFactor")
    filter.setValue(CIVector(x: 0, y: 100, z: 100, w: 100), forKey: "inputFocusRect") // works without this line

    let result = filter.outputImage
    self.imageView.image = UIImage(ciImage: result!)
}

【问题讨论】:

  • (1) 模糊 占用大量内存。您不能以这种方式模糊大图像。 (2)self.imageView.image = UIImage(ciImage: result!)不是将CIImage转为UIImage进行展示的正确方式。
  • 那么正确的方法是什么?
  • 另请注意,当我只模糊背景而不触摸“inputFocusRect”时,它可以工作吗?!

标签: ios swift core-image


【解决方案1】:

这可能不是 解决方案,但我注意到有两件事您可以尝试并报告结果:

  • 正如 matt 所指出的,在图像视图中使用图像之前,您应该先正确渲染图像。为此,您需要 CIContext(见下文)。
  • 深度模糊效果滤镜似乎有一个特殊的构造函数,它也链接到CIContext。

这里有一些你可以试试:

// create this only once and re-use it when possible, it's an expensive object
let ciContext = CIContext()

let filter = ciContext.depthBlurEffectFilter(for: mainImage, 
                                             disparityImage: disparityMap, 
                                             portraitEffectsMatte: nil, 
                                             // the orientation of you input image
                                             orientation: CGImagePropertyOrientation.up,
                                             options: nil)!
filter.setValue(0.1, forKey: "inputAperture")
filter.setValue(0.1, forKey: "inputScaleFactor")
filter.setValue(CIVector(x: 0, y: 100, z: 100, w: 100), forKey: "inputFocusRect")

let result = ciContext.createCGImage(filter.outputImage!, from: mainImage.extent)
self.imageView.image = UIImage(cgImage: result)

如果这有任何帮助会很有趣。

【讨论】:

  • 谢谢弗兰克。再次帮助你)。我刚刚尝试了您的代码,但它也没有奏效。再次出现同样的错误。
  • 这很不幸。你在什么设备上测试?你能告诉我inputFocusRect 是做什么的吗?我找不到任何文档...
  • 另外,请在不附加任何调试器的情况下在您的设备上测试您的应用作为发布版本。 Metal 调试器和分析器有时会在运行时增加很多开销。
  • 我不知道 inputFocusRect 做什么(虽然我猜它更好或相反地专注于所选区域)。我正在尝试 - 现在使用深度 API。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-16
相关资源
最近更新 更多