【问题标题】:Inconsistent brightness values for AVCaptureSessionAVCaptureSession 的亮度值不一致
【发布时间】: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


    【解决方案1】:

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

    device.setExposureModeCustomWithDuration(AVCaptureExposureDurationCurrent, iso: iso, completionHandler: nil) 
    

    然后您可以设置 ISO,这应该可以防止亮度值发生太大变化。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      • 2015-02-28
      • 2018-04-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-05
      • 2012-12-03
      相关资源
      最近更新 更多