Recently I'm trying to extract depth data and portrait effects matte data using portrait images. I tried to do that with portrait images (.HEIC format) taken by iPhone 11 with iOS 14.3. But I was unable to extract depth data and matte data from that images.
Here is the code snippet which I used to extract matte data from .HEIC format portrait image,
func portraitEffectsMatteImageAt(_ path: String) -> UIImage? { let bundlePath = Bundle.main.bundlePath
// Check that the image at given path contains auxiliary PEM data:
guard let fileURL = NSURL(fileURLWithPath: bundlePath).appendingPathComponent(path),
let source = CGImageSourceCreateWithURL(fileURL as CFURL, nil),
let auxiliaryInfoDict = CGImageSourceCopyAuxiliaryDataInfoAtIndex(source, 0, kCGImageAuxiliaryDataTypePortraitEffectsMatte) as? [AnyHashable: Any],
let matteData = try? AVPortraitEffectsMatte(fromDictionaryRepresentation: auxiliaryInfoDict),
let matteCIImage = CIImage(portaitEffectsMatte: matteData)
else {
return nil
}
return UIImage(ciImage: matteCIImage)
}
That function returns nil instead of returning matte image. So how can I extract matte data and depth data from .HEIC format images?
Thanks a lot