【问题标题】:Detect camera condition in AVCaptureSession swift快速检测 AVCaptureSession 中的相机状况
【发布时间】:2020-02-19 05:37:46
【问题描述】:

我正在开发一个 swift 应用程序,我想在摄像头不移动或用户专注于某物时在视频期间拍照。 我使用 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】:

    您可以尝试使用调整捕获设备的焦点属性(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 }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-22
      相关资源
      最近更新 更多