本文介绍了iOS + AVFoundation.具有相同手动曝光设置的不同照片亮度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用AVFoundation拍照.问题是,即使在持续设置曝光时间,ISO和白平衡的情况下,我也能获得具有不同亮度的照片.火炬,闪光灯和所有可能的稳定器均被禁用.

I use AVFoundation to take photos. Trouble is that even with constant settings of exposure duration, ISO and white balance I get photos with different brightness. Torch, flash and all possible stabilizations are disabled.

标准的Apple应用程序中也介绍了此问题,该应用程序介绍了如何使用相机: https://developer.apple.com/library/ios/samplecode/AVCam/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010112

This issue is also presented in standard Apple app introducing working with camera: https://developer.apple.com/library/ios/samplecode/AVCam/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010112

这是我通过此应用程序拍摄的视频,除了在会话初始化期间设置手动曝光外,没有任何更改:

This is the video I filmed via this app containing no changes except setting manual exposure during session initialization:

https://www.youtube.com/watch?v=g9NOWGVeftI

请注意,如果数码相机的曝光设置不变(不,不是已经设置了曝光设置并且已调用完成处理程序;已经设置了设置的那一刻,那该不该突然变亮).

Notice the sudden brightening what should not be if exposure settings of digital camera are constant (no, it is not moment when exposure settings have been set and completion handler has been called; settings are already set).

变亮并不总是发生,但是如果我将相机移开并再次瞄准物体,亮度可能会明显不同.但是,如果我在不移动相机的情况下进行一系列照片拍摄,亮度是相同的.

The brightening happens not always but anyway there can be significant brightness difference if I move camera away and aim to object again. But if I make series of photo without moving camera the brightnesses are same.

(当然,物体的照片是在相同的光照条件下拍摄的)

(Of course, object’s photos are taken in the same light circumstances)

这种变亮可能是设置自定义曝光设置的一部分(因为它通常是一开始就发生),而后期激活是我应该加快的过程,但我不知道该怎么做.

May be this brightening is a part of setting custom exposure settings (because it usually happens at first) and lt’s late activation is process I should speed up but I don’t know how to do it.

我对iPod Touch 5& iPad Air.我想它也可能在其他iOS设备上发生.

I have this effect on iPod Touch 5 & iPad Air. I suppose it can happen on other iOS devices too.

场景亮度似乎会影响最终图像的亮度(以及预览层的亮度).设备不仅设置了给定的曝光设置;它会基于当前场景亮度添加一些校正,并在可见场景的普通亮度发生很大变化时更改此校正.

It seems that scene brightness affects final image brightness (and preview layer’s brightness too). Device doesn’t just set given exposure settings; it adds some correction based on current scene brightness and changes this correction when common brightness of visible scene is changed a lot.

如果我用手关闭相机,请将手移开并拍照,它的亮度可能会比之前没有关闭相机的情况要亮.

If I close camera by my hand, move hand away and take a photo it can be brighter than one that captured without closing camera before.

可能不是亮度,而是对比度,因为当我将相机从白色显示器上移开时,当屏幕上的[相对较暗]的物体变得可见时,亮度可能会变亮.

May be it’s not [only] brightness but contrast because when I move camera away from white display there can be brightening in moment when [relatively dark] objects beyond screen became visible.

曝光目标偏移在增亮之前小于零,在增亮之后小于零.

Exposure target offset is little less than zero before the brightening and little more than zero after brightening.

我认为该值是该意外调整所基于的参数(例如在自动曝光模式下).

I supposed this value is parameter on what this unexpected adjustment is based (as in auto exposure mode).

但是尝试通过观察目标偏移量的变化并设置相等的曝光目标偏差来防止它失败,因为目标偏差一直在变化,并且不可能让工作的相机永久更改其目标偏差.

But attempts to prevent it via observing changes of target offset and setting equal exposure target bias failed because target offset is being changed all the time and it’s impossible to have working camera changing it’s target bias permanently.

尝试通过设置曝光目标偏差来强制调整,以使曝光目标偏移值在拍摄失败之前也远离零,这是因为什么也没有发生,并且在尝试补偿后我可以变亮.即使在自定义模式下,目标偏差也会影响曝光偏移(对客户可见),但似乎并不影响负责曝光的部件中的器件行为.

Attempts to force adjustment via setting exposure target bias making exposure target offset value far from zero before capturing failed too because nothing happens and I can have the brightening after attempt to compensate. Even in custom mode target bias affects exposure offset [visible to client] but it seems it does not affect device behavior in parts responsible for exposure.

我还发现在锁定的曝光模式下没有亮度跳变(或者我错过了…).我尝试在设置自定义曝光值后设置此模式,但是麻烦的是,在锁定模式下,设备不仅可以修复当前的曝光值,还可以进行初始调整以更改曝光设置.

I also found that there are no brightness jumps in locked exposure mode (or I missed them…). I tried to set this mode after setting custom exposure values but trouble is that in locked mode device not only fixes current exposure values but does initial adjustment what changes exposure settings.

我在拍照后从exif数据和从AVCaptureDevice实例获得的曝光值在跳转后不会更改.我尝试通过KVO观察曝光值,但没有任何可疑之处.当我设置自定义模式时,曝光时间和ISO更改了几次,然后调用完成处理程序.可以稍后变亮,但不会影响我可以获得的当前曝光值.

Exposure values I get from exif data and from AVCaptureDevice instance after taking photos are not changed after jump. I tried to observe exposure values via KVO but there’s nothing suspicious. When I set custom mode exposure duration and ISO are being changed few times and then completion handler is called. The brightening can be later, but it doesn’t affect current exposure values I can get.

这一切令人困惑.如何提供图像的亮度和曝光设置之间的直接关系?

All it is confusing. How can I provide straightforward relationship between image’s brightness and exposure settings?

推荐答案

修补后,我想出了如何轻松锁定曝光的方法.在主相机初始化期间,添加:

After tinkering I figured out how to easily lock your exposure.During primary camera initialization add:

device.exposureMode = AVCaptureDevice.ExposureMode.custom

设备锁定进行配置后立即

as soon as the device is locked for config

和(非常重要)

device.exposureMode = AVCaptureDevice.ExposureMode.locked

这两个都确保:
1.您可以使用自定义设置来初始化相机
2.更改后,相机保持完全锁定状态

These both ensure that:
1. You get to initialize the camera with your custom settings
2. The camera remains completely locked after changes are made

您的相机初始化代码应如下所示:

Your camera init code should look something like this:

 try device.lockForConfiguration()
          device.exposureMode = AVCaptureDevice.ExposureMode.custom
          device.setExposureModeCustom(duration: durationCust, iso: minISO, completionHandler: nil)
          device.setWhiteBalanceModeLocked(with: deviceGains) {
                    (timestamp:CMTime) -> Void in
            }
          device.exposureMode = AVCaptureDevice.ExposureMode.locked
            device.unlockForConfiguration()

当您要主动更改曝光参数时,请勿在实际更改曝光范围之外重新将曝光声明为锁定或自定义.函数中的代码应如下所示:

When you want to actively change the exposure parameters do not re-declare the exposure as locked or custom outside of actually changing the exposure. The code in your function should look something like this:

try device.lockForConfiguration()
                 device.setExposureModeCustom(duration: durationCust, iso: minISO, completionHandler: nil)
             device.unlockForConfiguration()

我很高兴弄清楚这一点-希望有人觉得有帮助:)

I was happy to figure this out - I hope someone finds it helpful :)

这篇关于iOS + AVFoundation.具有相同手动曝光设置的不同照片亮度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 18:36