I've come across a couple of questions on this topic that don't have answers, such as this one: https://forums.developer.apple.com/message/280867#280867
I am trying to pass a flag to my image capturing service to specify whether depth data should be filtered or not.
I should be able to set this flag by setting `AVCapturePhotoSettings.isDepthDataFiltered = false` according to the documentation: https://developer.apple.com/documentation/avfoundation/avdepthdata/2881224-isdepthdatafiltered
However, when I set this flag and capture the output, the value of `photo.depthData?.isDepthDataFiltered` always reports true in the delegate function. What am I doing wrong?
Here is the class I'm using to get image data:
class ImageService : NSObject {
var session: AVCaptureSession?
var videoPreviewLayer: AVCaptureVideoPreviewLayer?
var capturePhotoOutput: AVCapturePhotoOutput?
var counter = 0
override init() {
AVCaptureDevice.requestAccess(for: .video, completionHandler: { _ in })
let captureDevice = AVCaptureDevice.default(.builtInDualCamera, for: .video, position: .back)
do{
let input = try AVCaptureDeviceInput(device: captureDevice!)
self.capturePhotoOutput = AVCapturePhotoOutput()
self.session = AVCaptureSession()
self.session?.beginConfiguration()
self.session?.sessionPreset = .photo
self.session?.addInput(input)
self.videoPreviewLayer = AVCaptureVideoPreviewLayer(session: self.session!)
self.videoPreviewLayer?.videoGravity = AVLayerVideoGravity.resizeAspectFill
self.session?.addOutput(self.capturePhotoOutput!)
self.session?.commitConfiguration()
self.capturePhotoOutput?.isDepthDataDeliveryEnabled = true
self.capturePhotoOutput?.isDualCameraDualPhotoDeliveryEnabled = true
self.session?.startRunning()
}
catch{
print(error)
}
}
func grab_data(filterDepth:Bool){
print ("Passed in: \(filterDepth)")
guard let capturePhotoOutput = self.capturePhotoOutput else { return }
let photoSettings = AVCapturePhotoSettings()
photoSettings.isDepthDataDeliveryEnabled = true
photoSettings.isDualCameraDualPhotoDeliveryEnabled = true
photoSettings.isCameraCalibrationDataDeliveryEnabled = true
photoSettings.isDepthDataFiltered = filterDepth
capturePhotoOutput.capturePhoto(with: photoSettings, delegate: self)
}
deinit {
self.session?.stopRunning()
}
}
extension ImageService : AVCapturePhotoCaptureDelegate {
func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {
if (photo.depthData != nil)
{
print("Depth Filtering")
print(photo.depthData?.isDepthDataFiltered)
}
}
}