0

我正在开发一个快速应用程序,我想在相机不移动或用户专注于某物时在视频期间拍照。我使用了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)
        }
    }

有什么解决办法吗

4

1 回答 1

0

您可以尝试使用调整捕获设备的焦点属性(AVCaptureDevice),当它为 false 时,焦点是稳定的。请参阅下面的详细文档。

/**
 @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 }
于 2020-02-19T06:06:10.873 回答