访问用于相机曝光和快门速度的 iOS 6 新 API
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12635446/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Accessing iOS 6 new APIs for camera exposure and shutter speed
提问by Adam Pop?awski
On Apple's iOS 6.0 feature page, it used to say
在 Apple 的iOS 6.0 功能页面上,它曾经说过
Take advantage of the built-in camera's advanced features. New APIs let you control focus, exposure, and region of interest. You can also access and display faces with face detection APIs, and leverage hardware-enabled video stabilization.
充分利用内置相机的高级功能。新的 API 可让您控制焦点、曝光和感兴趣的区域。您还可以使用人脸检测 API 访问和显示人脸,并利用支持硬件的视频稳定功能。
This text has since been removed, and I can't find new methods in the API for controlling exposure. In class AVCaptureDevice
under "Exposure Settings" there is no new property/method for iOS 6.0. Do you know where i can find new features for exposure in API?
此文字已被删除,我无法在 API 中找到控制曝光的新方法。在AVCaptureDevice
“曝光设置”下的课程中,iOS 6.0 没有新的属性/方法。你知道我在哪里可以找到 API 中暴露的新功能吗?
回答by Michael Grinich
It's true that there is an -exposureMode
property on AVCaptureDevice
, but that's only for setting the mode (off/auto/continuous) and not the actual f-stop, SS, or ISO. Camera apps that provide "exposure" control all seem to do it through post-processing.
确实有一个-exposureMode
属性 on AVCaptureDevice
,但这仅用于设置模式(关闭/自动/连续),而不是实际的 f-stop、SS 或 ISO。提供“曝光”控制的相机应用程序似乎都是通过后处理来实现的。
However, it seems there are undocumented APIs in the framework to do this. Check out the full headers for AVCaptureDevice.h
(via a class-dump) and note the following methods:
但是,框架中似乎有未公开的 API 来执行此操作。查看(通过class-dump)的完整标题AVCaptureDevice.h
并注意以下方法:
- (void)setManualExposureSupportEnabled:(BOOL)arg1;
- (BOOL)isManualExposureSupportEnabled;
- (void)setExposureGain:(float)arg1;
- (float)exposureGain;
- (void)setExposureDuration:(struct { long long x1; int x2; unsigned int x3; long long x4; })arg1;
- (struct { long long x1; int x2; unsigned int x3; long long x4; })exposureDuration;
- (void)setExposureMode:(int)arg1;
- (int)exposureMode;
- (BOOL)isExposureModeSupported:(int)arg1;
My guess is gain
is equivalent f-stop (fixed aperture), and duration
is shutter speed. I wonder if these are used for the iPhone 5's low-light boost mode.
我的猜测是gain
等效 f-stop(固定光圈),并且duration
是快门速度。我想知道这些是否用于 iPhone 5 的低光增强模式。
You can also use otool
to poke around and try to piece together the symbols. There's likely a new constant in exposureMode
for enabling manual control, and exposureDuration
seems like it has flags too. When calling these, make sure to use the new -isExposureModeSupported:
and also call -respondsToSelector:
to check compatibility.
您还可以使用otool
戳并尝试将符号拼凑在一起。可能有一个exposureMode
用于启用手动控制的新常量,并且exposureDuration
它似乎也有标志。调用这些时,请确保使用新的-isExposureModeSupported:
并调用-respondsToSelector:
以检查兼容性。
As always, using private APIs is frowned upon by Apple and is cause for rejection from the App Store. There might be ways around this, such as hiding the calls using -performSelector:
or obc_msgsend
with rot13 strings or something, as I'm pretty sure they only do static analysis on the app binary.
与往常一样,使用私有 API 是 Apple 不赞成的,也是 App Store 拒绝的原因。附近可能有这种方式,如使用隐藏来电-performSelector:
或obc_msgsend
用ROT13串什么的,因为我敢肯定,他们只做上的应用程序二进制静态分析。
回答by user3115647
I've managed to 'trick' the camera into running a shorter exposure time, but I suspect it will only be of use to those doing similar (macro) image acquires. I first set up AVCaptureDevice to use AVCaptureExposureModeContinuousAutoExposure and set the flash to TorchMode. I then UnlockForConfiguration and set up a key-value observer to watch for adjustingExposure to finish. I then re-lock the device, flip to AVCaptureExposureModeLocked, and turn off the Torch. This has the effect of brute-force setting a shorter shutter speed than what the camera would select on the un-illuminated scene. By playing with the Torch level I can set any relative shutter speed value I want (it would be best of course to leave the torch on, but in my application it produces glare on the subject). Again this only really works when your object distance is very close (less than say 6 inches), but it's allowed me to eliminate hand shake blurring in my close-up images. The down side is that the images are darker since I don't have a way of spoofing the camera gain, but not a problem in my particular application.
我已经设法“欺骗”相机运行更短的曝光时间,但我怀疑它只会对那些进行类似(微距)图像采集的人有用。我首先设置 AVCaptureDevice 以使用 AVCaptureExposureModeContinuousAutoExposure 并将闪光灯设置为 TorchMode。然后我 UnlockForConfiguration 并设置一个键值观察器来观察 adjustExposure 的完成。然后我重新锁定设备,切换到 AVCaptureExposureModeLocked,然后关闭 Torch。这具有蛮力设置比相机在未照明场景中选择的快门速度更短的效果。通过使用 Torch 级别,我可以设置我想要的任何相对快门速度值(当然最好让手电筒保持开启状态,但在我的应用程序中它会在主体上产生眩光)。同样,这仅在您的物距非常近(小于 6 英寸)时才真正有效,但它允许我消除特写图像中的手抖动模糊。不利的一面是图像更暗,因为我没有办法欺骗相机增益,但在我的特定应用程序中不是问题。
回答by Bretton Wade
As a follow-up to Michael Grinich's excellent information, I found that there is an order dependency on some of the calls in the private API. To use "manual" exposure controls, you have to enable them beforeyou set the mode, like so:
作为 Michael Grinich 优秀资料的后续,我发现私有 API 中的某些调用存在顺序依赖性。要使用“手动”曝光控制,您必须在设置模式之前启用它们,如下所示:
#define AVCaptureExposureModeManual 3
NSError* error = nil;
if ([captureDevice lockForConfiguration:&error]) {
captureDevice.manualExposureSupportEnabled = YES;
if ([captureDevice isExposureModeSupported:AVCaptureExposureModeManual]) {
captureDevice.exposureMode = AVCaptureExposureModeManual;
captureDevice.exposureGain = ...;
captureDevice.exposureDuration = {...};
}
[captureDevice unlockForConfiguration];
}
All of this is demonstrated in iOS-ManualCamera.
所有这些都在iOS-ManualCamera 中进行了演示。
回答by Freney
It looks like they've updated that linked text—there's no mention of new APIs for exposure:
看起来他们已经更新了链接文本——没有提到新的公开 API:
Use powerful new features of the built-in camera. New APIs support real-time video stabilization, an improved LED flash, and face detection and display. You can get reports of dropped frames during capture and leverage new utilities to map UI touches to focus and exposure commands. And apps that support iPhone 5 can take advantage of low light boost mode.
使用内置相机的强大新功能。新的 API 支持实时视频稳定、改进的 LED 闪光灯以及面部检测和显示。您可以在捕获期间获取丢帧报告,并利用新实用程序将 UI 触摸映射到对焦和曝光命令。支持 iPhone 5 的应用程序可以利用弱光增强模式。
There isan opt-in low-light boost mode for iPhone 5, detailed here by Jim Rhoades(and in this developer forum post, log-in required).
回答by Simon Epskamp
Starting with iOS 8.0, this is now finally possible.
从 iOS 8.0 开始,现在终于可以了。
See setExposureModeCustomWithDurationetc. in the Apple documentation.
请参阅Apple 文档中的setExposureModeCustomWithDuration等。