【发布时间】:2015-10-30 17:38:43
【问题描述】:
我正在尝试在使用我的 iPhone 前置摄像头的 AVCapture 会话期间使用 didOutputSampleBuffer 委托从 AVCaptureVideoDataOutput 对象获取传递给 AVCaptureVideoDataOutputSampleBufferDelegate 的帧的亮度:
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()
但这似乎没有奏效。实在想不通是什么原因造成的。
谢谢
【问题讨论】:
标签: ios camera avcapturesession brightness