10

我有一个程序可以使用默认参数拍摄视频,并且当我移动相机时会自动调整曝光、对焦和白平衡。我想在程序中添加 2 个按钮:LOCK 和 PRESET。按下 LOCK 按钮时,曝光、对焦和白平衡将被固定,它们的值将作为用户设置存储。PRESET 按钮用于设置相机的用户设置,以确保我们可以拍摄具有相同曝光、对焦和白平衡值的所有视频。

锁定部分很简单,我只需要更改模式,所以我想知道是否有任何方法可以获取和设置曝光、对焦和白平衡的值。

以曝光为例,默认情况下,exposureMode 设置为 AVCaptureExposureModeContinuousAutoExposure,也就是说,当我拿着 iPhone 拍摄视频时,会自动调整曝光,以确保我们在明亮或黑暗的环境中都能清晰地看到场景。

AVCaptureDevice* pCaptureDevice = [self videoDeviceWithPosition:AVCaptureDevicePositionBack];
[pCaptureDevice lockForConfiguration:nil];
[pCaptureDevice setExposureMode:AVCaptureExposureModeContinuousAutoExposure];
[pCaptureDevice unlockForConfiguration];

当按下LOCK按钮时,我将exposureMode更改为AVCaptureExposureModeLocked,这样当前的曝光值就不会再改变了。

[pCaptureDevice lockForConfiguration:nil];
[pCaptureDevice setExposureMode:AVCaptureExposureModeLocked];
[pCaptureDevice unlockForConfiguration];

但是,如何获得按下按钮时的曝光值?更重要的是,当按下 PRESET 时,如何将曝光值设置回 AVCaptureDevice。

我在论坛里搜索,只找到了 Michael Grinich 的帖子:Accessing iOS 6 new APIs for camera exposure and shutter speed。我按照他的发现并尝试使用私有API来获取和设置exposureGain和exposureDuration,但我发现在AVCaptureExposureModeContinuousAutoExposure模式下,当我将相机从黑暗环境移动到明亮环境时,这两个值从未改变(exposureGain = 1.0和曝光持续时间 = {1, 30, 1, 0})。设置它们根本不会改变曝光。

[pCaptureDevice lockForConfiguration:nil];
[pCaptureDevice setExposureMode:AVCaptureExposureModeLocked];
[pCaptureDevice setManualExposureSupportEnabled:YES];
NSLog(@"exposure gain: %f", [pCaptureDevice exposureGain]);
[pCaptureDevice setExposureGain:3.0];
NSLog(@"exposure gain: %f", [pCaptureDevice exposureGain]);
[pCaptureDevice unlockForConfiguration];

有人可以帮我解决这个问题吗?首先十分感谢!

4

2 回答 2

1

我添加了一个答案,可以帮助您访问 iOS 6 new APIs for camera exposure and shutter speed。我可以在这里添加更多细节......

手动设置焦点与我为设置曝光概述的结构完全相同。那是:

#define AVCaptureFocusModeManual     3
NSError*    error = nil;
if ([captureDevice lockForConfiguration:&error]) {
    captureDevice.manualFocusSupportEnabled = YES;
    if ([captureDevice isFocusModeSupported:AVCaptureFocusModeManual]) {
        captureDevice.focusMode = AVCaptureFocusModeManual;
        // this is a value [0..1]
        captureDevice.focusPosition = ...;
    }
    [captureDevice unlockForConfiguration];
}

白平衡似乎没有像曝光和对焦那样的特殊模式。不要将 WhiteBalanceMode 设置为锁定,否则您似乎可以只设置色温:

// this is also a value [0..1]
captureDevice.whiteBalanceTemperature = ...;
于 2014-01-30T08:24:40.933 回答
0

要设置手动固定曝光值和 ISO,您现在可以执行以下操作:

[Device lockForConfiguration:nil];
[Device setExposureModeCustomWithDuration:CMTimeMake(5, 100) ISO:AVCaptureISOCurrent completionHandler:nil]; //currently set to 50ms for example
[Device unlockForConfiguration];

你可以在这里参考它的文档:https ://developer.apple.com/reference/avfoundation/avcapturedevice/1624646-setexposuremodecustomwithduratio?language=objc

于 2017-05-24T20:46:12.317 回答