Tuesday, 28 May 2019

Smooth focus ramp on AVCaptureDevice

I am using AVCaptureDevice setFocusModeLocked to implement a focus ramp from point A to point B. The way I do it is I define delta to be something like 0.03 and then repeatedly call the API to set lensPosition.

   device.setFocusModeLocked(lensPosition: pointA, completionHandler: {[weak self] (time) in
            DispatchQueue.main.asyncAfter(deadline: DispatchTime.now(), execute: { [weak self] in

                if pointA == pointB {
                    device.unlockForConfiguration()
                    return
                }

                var beginPoint = fmax(currentLensPosition + delta),Float(0))
                let endPoint = fmin(pointB, Float(1.0))


                self?.focusRampRecursive( beginPoint,
                                          pointB:endPoint,
                                          delta: delta,
                                          device: device)
            })
        })

The problem is ramp is not smooth. There are jumps visible when the ramp happens. How can I make it smooth?



from Smooth focus ramp on AVCaptureDevice

No comments:

Post a Comment