【问题标题】:How to produce AVFoundation Camera Images as bright as those taken with the native camera?如何生成与使用原生相机拍摄的图像一样明亮的 AVFoundation 相机图像?
【发布时间】:2014-02-06 08:32:49
【问题描述】:

我玩过 AutoFocus、AutoExposure、AutoWhiteBalance 和 LowLightBoost,但仍然可以让相机图像显示得与使用 iPhone 5 原生相机查看/捕获的图像一样亮。

不知道我做错了什么。以下是按下屏幕时设置自动相机功能的主要功能。自动对焦有效。但不确定自动曝光、白平衡和 LowLightBoost 是否也能正常工作,因为查看的暗项目不会像原生相机那样变亮。 以下大部分代码取自 iosDev 中心网站上发布的 AVCam 示例。

提前致谢!

- (IBAction)focusAndExposeTap:(UIGestureRecognizer *)gestureRecognizer
{
    CGPoint devicePoint = [(AVCaptureVideoPreviewLayer *)[[self previewView] layer] captureDevicePointOfInterestForPoint:[gestureRecognizer locationInView:[gestureRecognizer view]]];
    [self focusWithMode:AVCaptureFocusModeAutoFocus exposeWithMode:AVCaptureExposureModeAutoExpose whiteBalanceWithMode:AVCaptureWhiteBalanceModeContinuousAutoWhiteBalance atDevicePoint:devicePoint monitorSubjectAreaChange:YES];
}

- (void)focusWithMode:(AVCaptureFocusMode)focusMode exposeWithMode:(AVCaptureExposureMode)exposureMode whiteBalanceWithMode:(AVCaptureWhiteBalanceMode)whiteBalanceMode atDevicePoint:(CGPoint)point monitorSubjectAreaChange:(BOOL)monitorSubjectAreaChange{
dispatch_async([self sessionQueue], ^{
    AVCaptureDevice *device = [[self videoDeviceInput] device];
    NSError *error = nil;
    if ([device lockForConfiguration:&error])
    {
        if ([device isFocusPointOfInterestSupported] && [device isFocusModeSupported:focusMode])
        {
            [device setFocusMode:focusMode];
            [device setFocusPointOfInterest:point];
        }
        NSLog(@"Pre-Exposure Mode Support?: %hhd", [device isExposurePointOfInterestSupported]);
        if ([device isExposurePointOfInterestSupported] && [device isExposureModeSupported:exposureMode])
        {
            [device setExposureMode:exposureMode];
            [device setExposurePointOfInterest:point];
        }
        NSLog(@"Pre-White Balance mode Support? %hhd", [device isWhiteBalanceModeSupported:whiteBalanceMode]);
        if ([device isWhiteBalanceModeSupported:whiteBalanceMode])
        {
            [device setWhiteBalanceMode:whiteBalanceMode];
        }
        NSLog(@"Pre Low light mode: %hhd", [device isLowLightBoostSupported]);
        if ([device isLowLightBoostSupported]){
            [device setAutomaticallyEnablesLowLightBoostWhenAvailable:YES];
        }
        [device setSubjectAreaChangeMonitoringEnabled:monitorSubjectAreaChange];
        [device unlockForConfiguration];
    }
    else
    {
        NSLog(@"%@", error);
    }
});
}

【问题讨论】:

  • 您找到解决方案了吗?

标签: ios iphone camera avfoundation brightness


【解决方案1】:

我的猜测是问题出在您的AVCaptureExposureMode 上。正如你可以从我的线程here 中看到的那样,iOS 7 目前在任何设备上都不支持AVCaptureExposureModeAutoExpose。因此,exposurePointOfInterest 将不会设置在您想要的点上。

你的程序甚至不会输入你下面的sn-p代码(你可以自己检查):

if ([device isExposurePointOfInterestSupported] && [device isExposureModeSupported:exposureMode])
        {
            [device setExposureMode:exposureMode];
            [device setExposurePointOfInterest:point];
        }

如果您想拥有自动曝光功能,您可以使用AVCaptureExposureModeContinuousAutoExpose 设置特定点的曝光。然后监听(key-value observe KVO)AVCaptureDeviceisAdjustingExposure属性,知道曝光何时完成调整。完成后,将ExposureMode 设置为AVCaptureExposureModeLocked

如果这没有帮助,请告诉我,否则您可以接受并投票赞成这个答案:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-13
    • 2011-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-15
    • 2017-09-20
    相关资源
    最近更新 更多