Ios AVCaptureSession的亮度值不一致

Ios AVCaptureSession的亮度值不一致,ios,camera,avcapturesession,brightness,Ios,Camera,Avcapturesession,Brightness,我正在尝试在AVCapture会话期间获取从AVCaptureVideoDataOutputSampleBuffer对象传递给AVCaptureVideoDataOutputSampleBufferDelegate的帧的亮度,该会话使用我的iPhone的前摄像头,使用didOutputSampleBuffer委托: func captureOutput(captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMS

我正在尝试在AVCapture会话期间获取从AVCaptureVideoDataOutputSampleBuffer对象传递给AVCaptureVideoDataOutputSampleBufferDelegate的帧的亮度,该会话使用我的iPhone的前摄像头,使用didOutputSampleBuffer委托:

func captureOutput(captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, fromConnection connection: AVCaptureConnection!) {
        let dict = CMGetAttachment(sampleBuffer, kCGImagePropertyExifDictionary, nil)
        if let brightness = dict!["BrightnessValue"] as? Double {
            print(brightness)    
        }
    }
这一亮度保持一致是很重要的。在一个会话中,亮度是一致的,但如果我以编程方式或通过锁定设备/退出应用程序停止并重新启动会话,则亮度值似乎会发生变化。我的意思是,当我在会话之间阻挡相机时接收到的亮度值会发生变化

我已尝试修复所有我认为可能影响视亮度的相机设置:

try videoCaptureDevice.lockForConfiguration()

        videoCaptureDevice.autoFocusRangeRestriction = AVCaptureAutoFocusRangeRestriction.None
        videoCaptureDevice.smoothAutoFocusEnabled = false
        videoCaptureDevice.setExposureTargetBias(0.5) { (CMTime) -> Void in

        }

        if videoCaptureDevice.lowLightBoostEnabled {
            videoCaptureDevice.automaticallyEnablesLowLightBoostWhenAvailable = false
        }

        videoCaptureDevice.videoZoomFactor = 1.0
        videoCaptureDevice.automaticallyAdjustsVideoHDREnabled = false

        videoCaptureDevice.exposureMode = AVCaptureExposureMode.Locked

        videoCaptureDevice.setWhiteBalanceModeLockedWithDeviceWhiteBalanceGains(AVCaptureWhiteBalanceGains.init(redGain: 1.0, greenGain: 1.0, blueGain: 1.0), completionHandler: { (CMTime) -> Void in

        })

        videoCaptureDevice.setFocusModeLockedWithLensPosition(0.5) { (CMTime) -> Void in

        }

        videoCaptureDevice.unlockForConfiguration()
但这似乎不起作用。我真的不知道是什么引起的


谢谢

我的回答可能晚了将近一年,但它仍然可能对某些人有所帮助。看起来您没有尝试设置ISO。如果您使用:

device.setExposureModeCustomWithDuration(AVCaptureExposureDurationCurrent, iso: iso, completionHandler: nil) 
然后可以设置ISO,这样可以防止亮度值变化过大


还有一些提示,请确保只执行一次,否则在第二次调用后,您的值将再次不一致。在调用上述方法之前,您还必须先锁定设备进行配置。

我的回答可能晚了将近一年,但它仍然可能对某些人有所帮助。看起来您没有尝试设置ISO。如果您使用:

device.setExposureModeCustomWithDuration(AVCaptureExposureDurationCurrent, iso: iso, completionHandler: nil) 
然后可以设置ISO,这样可以防止亮度值变化过大


还有一些提示,请确保只执行一次,否则在第二次调用后,您的值将再次不一致。在调用上述方法之前,您还必须先锁定设备进行配置。

我的回答可能晚了将近一年,但它仍然可能对某些人有所帮助。看起来您没有尝试设置ISO。如果您使用:

device.setExposureModeCustomWithDuration(AVCaptureExposureDurationCurrent, iso: iso, completionHandler: nil) 
然后,您可以设置ISO,这将阻止亮度值更改过多


还有一些提示,请确保只执行一次,否则在第二次调用后,您的值将再次不一致。在调用上述方法之前,您还必须先锁定设备进行配置。

我的回答可能晚了将近一年,但它仍然可能对某些人有所帮助。看起来您没有尝试设置ISO。如果您使用:

device.setExposureModeCustomWithDuration(AVCaptureExposureDurationCurrent, iso: iso, completionHandler: nil) 
然后可以设置ISO,这样可以防止亮度值变化过大

还有一些提示,请确保只执行一次,否则在第二次调用后,您的值将再次不一致。在调用上述方法之前,还必须先锁定设备进行配置