Reputation: 123
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
Reputation: 10383
This is maybe not the solution, but I noticed two things that you could try and report back the results:
CIContext
for that (see below).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