我正在尝试读取深度图并将其覆盖在PHAsset的UIImageView上。
到目前为止,我有这个:
PHImageManager.default().requestImageData(for: self.asset!, options: nil, resultHandler:{ (data, responseString, orientation, info) -> Void in
if let imageData: Data = data {
if let imageSource = CGImageSourceCreateWithData(imageData as CFData, nil) {
let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil)! as NSDictionary
let auxDataType = kCGImageAuxiliaryDataTypeDisparity
let auxDataInfo = CGImageSourceCopyAuxiliaryDataInfoAtIndex(imageSource, 0, auxDataType)
if auxDataInfo == nil {
print ("NO DEPTH")
} else {
do {
var depthData = try AVDepthData(fromDictionaryRepresentation: auxDataInfo as! [AnyHashable : Any])
if depthData.depthDataType != kCVPixelFormatType_DisparityFloat16 {
depthData = depthData.converting(toDepthDataType: kCVPixelFormatType_DisparityFloat16)
}
let depthMap : CVPixelBuffer = depthData.depthDataMap
var ciImage = CIImage(cvPixelBuffer: depthMap)
ciImage = ciImage.applyingFilter("CIDisparityToDepth", parameters: [:])
DispatchQueue.main.async {
self.imageView.image = UIImage(ciImage: ciImage)
}
}
catch { }
}
}
}
})
问题: