eral
eral

Reputation: 123

CIDepthBlurEffect Failed to render part of the image because of the memory requirement

CIDepthBlurEffect normally works on my phone with ios 12.4 but it gives the following errors when I try to examine "inputFocusRect" parameter? Also no error is produced when I set y : 0; however image is not processed. Any idea? Thanks.

Here is the code:

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!)
}

Upvotes: 0

Views: 405

Answers (1)

Frank Rupprecht
Frank Rupprecht

Reputation: 10383

This is maybe not the solution, but I noticed two things that you could try and report back the results:

  • As matt pointed out, you should properly render the image first before using it in an image view. You need a CIContext for that (see below).
  • There seem to be a special constructor for the depth blur effect filter that is also linked to a CIContext.

Here's some could you can try:

// 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)

Would be interesting to hear if this helps in any way.

Upvotes: 2

Related Questions