检测AVCaptureSession swift中的摄像机条件

问题描述 投票:0回答:1

我正在开发一种快速的应用程序,并且我想在视频过程中相机不动或用户聚焦时拍摄照片。我使用了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)
        }
    }

对此有任何解决方案

swift avfoundation avcapturesession avcapturevideodataoutput
1个回答
0
投票

您可以尝试使用捕获设备(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 }
© www.soinside.com 2019 - 2024. All rights reserved.