AVCaptureTorchModeAuto不会连续更新手电筒模式 [英] AVCaptureTorchModeAuto does not continuously update torch mode

查看:1429
本文介绍了AVCaptureTorchModeAuto不会连续更新手电筒模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个应用程序,根据照明条件自动打开iOS设备背面的手电筒。

I am writing an app that automatically turns on the torch on the back of an iOS device depending on lighting conditions. The app renders a live camera view, and does not record the video.

我已尝试使用 AVCaptureTorchModeAuto ,但是它只是似乎在捕获会话开始时测量图像的亮度,并相应地设置割炬。

I have tried using AVCaptureTorchModeAuto, but it only seems to measure the brightness of the image at the start of the capture session, and set the torch accordingly. The setting then does not change afterwards, regardless of the brightness of the camera image.

可以让系统连续调整割炬,如文档? p>

It is possible to have the system adjust the torch continuously, like stated in the documentation?


捕获设备持续监测光照水平,并在必要时使用割炬。

The capture device continuously monitors light levels and uses the torch when necessary.

在iOS 4.0及更高版本中。

Available in iOS 4.0 and later.


推荐答案

因此,AVCaptureTorchModeAuto无法按照您的预期工作。

With current set of APIs, the brightness sampling is only done at the start of the recording. So AVCaptureTorchModeAuto does not work as you expect.

现在关于问题中讨论的用例:

Now about the use case discussed in the question:

可能性1:
使用后置摄像头进行亮度检测:

Possibility 1: Use Rear camera for brightness detection:

一旦手电筒出现,分析捕获的流将不会告诉房间亮度的当前情况,因为手电筒将导致化妆品亮度。

Once torch comes up, analysis of the captured stream will not tell the current situation of room brightness, as Torch will cause cosmetic brightness.

因此,为了获得真正的亮度值,需要及时切换开关,这是在大多数情况下不是非常通用和方便

So in order to get the real brightness value would have to require to switch on-off on timely basis, which is not very generic and convenient in most of the cases.

获得亮度值以决定是否启用火炬。

Getting brightness value to decide enabling of Torch or not.

- (void)captureOutput:(AVCaptureOutput *)captureOutput
      didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
             fromConnection:(AVCaptureConnection *)connection
{
  CFDictionaryRef metadataDict = CMCopyDictionaryOfAttachments(NULL, 
    sampleBuffer, kCMAttachmentMode_ShouldPropagate);
  NSDictionary *metadata = [[NSMutableDictionary alloc] 
    initWithDictionary:(__bridge NSDictionary*)metadataDict];
  CFRelease(metadataDict);
  NSDictionary *exifMetadata = [[metadata 
    objectForKey:(NSString *)kCGImagePropertyExifDictionary] mutableCopy];
  float brightnessValue = [[exifMetadata 
    objectForKey:(NSString *)kCGImagePropertyExifBrightnessValue] floatValue];
}

可能性2:用于亮度检测的相机:

Possibility 2: Use Front Camera for brightness detection:

前置摄像头不允许使用手电筒。

Torch is not permitted with front camera.

这篇关于AVCaptureTorchModeAuto不会连续更新手电筒模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆