Slide 35
Slide 35 text
/// - Tag: DidFinishProcessingPhoto
func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto,
error: Error?) {
photoProcessingHandler(false)
if let error = error {
print("Error capturing photo: \(error)")
photoData = nil
} else {
// Cache the HEIF representation of the data.
photoData = photo
}
// Cache the depth data, if it exists, as a disparity map.
logger.log("DidFinishProcessingPhoto: photo=\(String(describing: photo))")
if let depthData = photo.depthData?.converting(toDepthDataType:
kCVPixelFormatType_DisparityFloat32),
let colorSpace = CGColorSpace(name: CGColorSpace.linearGray) {
let depthImage = CIImage( cvImageBuffer: depthData.depthDataMap,
options: [ .auxiliaryDisparity: true ] )
depthMapData = context.tiffRepresentation(of: depthImage,
format: .Lf,
colorSpace: colorSpace,
options: [.disparityImage: depthImage])
} else {
logger.error("colorSpace .linearGray not available... can't save depth data!")
depthMapData = nil
}
}
ਂϚοϓΛอଘ