Определить состояние камеры в AVCaptureSession Swift - PullRequest
0 голосов
/ 19 февраля 2020

Я работаю над быстрым приложением и хочу сделать снимок во время видео, когда камера не движется или когда пользователь фокусируется на чем-то. я использовал AVCaptureVideoDataOutputSampleBufferDelegate * метод captureOutput, который дает мне изображение каждый раз после запуска камеры. но я хочу брать только тогда, когда камера не движется или не сфокусирована.

func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {        
        print("didOutput")
        guard let hasImage = CMSampleBufferGetImageBuffer(sampleBuffer) else {
            print("no image")
            return
        }
        let ciimage : CIImage = CIImage(cvPixelBuffer: hasImage)
        DispatchQueue.main.async {
            self.liveCamImage = self.convert(cmage: ciimage)
        }
    }

есть ли решение для этого

1 Ответ

0 голосов
/ 19 февраля 2020

Вы можете попробовать использовать свойство настройки фокуса вашего устройства захвата (AVCaptureDevice), когда оно ложно, фокусировка стабильна. См. Подробную документацию ниже.

/**
 @property adjustingFocus
 @abstract
    Indicates whether the receiver is currently performing a focus scan to adjust focus.

 @discussion
    The value of this property is a BOOL indicating whether the receiver's camera focus is being automatically adjusted by means of a focus scan, because its focus mode is AVCaptureFocusModeAutoFocus or AVCaptureFocusModeContinuousAutoFocus. Clients can observe the value of this property to determine whether the camera's focus is stable.
 @seealso lensPosition
 @seealso AVCaptureAutoFocusSystem
 */
open var isAdjustingFocus: Bool { get }
...