【问题标题】:AVCaptureDevice Low Light Boost Does Not workAVCaptureDevice 低光照增强不起作用
【发布时间】:2014-03-17 05:54:31
【问题描述】:

AVCaptureDevice 的低光增强属性未在应启用时启用。我正在使用 iOS 6 的 iPhone 5 上对此进行测试。代码如下:

    // finds a device that supports the video media type
    AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    NSArray *allDevices = [AVCaptureDevice devices];
    for (AVCaptureDevice *currentDevice in allDevices) {
        if (currentDevice.position == AVCaptureDevicePositionBack) {
            device = currentDevice;
        }
    }

    NSError *deviceError = nil;
    if (device.isFlashAvailable){
        [device lockForConfiguration:&deviceError];
        device.flashMode = AVCaptureFlashModeAuto;
        [device unlockForConfiguration];
    }
    if ([device respondsToSelector:@selector(isLowLightBoostSupported)]) {
        if ([device lockForConfiguration:nil]) {
            if (device.isLowLightBoostSupported)
                device.automaticallyEnablesLowLightBoostWhenAvailable = YES;
                [device unlockForConfiguration];
        }
    }
    if ([device isExposureModeSupported:AVCaptureExposureModeContinuousAutoExposure]) {
        [device lockForConfiguration:&deviceError];
        device.exposureMode = AVCaptureExposureModeContinuousAutoExposure;
        // CODE FOR device.exposurePointOfInterest determined from wherever the face is based off of the faceScan method
        [device unlockForConfiguration];
    }

    AVCaptureDeviceInput *newVideoInput = [AVCaptureDeviceInput deviceInputWithDevice:device error:&deviceError];

    AVCaptureStillImageOutput *newStillImageOutput = [[AVCaptureStillImageOutput alloc] init];

    NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys:
                                AVVideoCodecJPEG, AVVideoCodecKey,
                                nil];


    [newStillImageOutput setOutputSettings:outputSettings];


    self.sess = [[AVCaptureSession alloc] init];

    if ([self.sess canAddInput:newVideoInput]) {
        [self.sess addInput:newVideoInput];
    }
    if ([self.sess canAddOutput:newStillImageOutput]) {
        [self.sess addOutput:newStillImageOutput];
    }
    self.stillImageOutput = newStillImageOutput;

    if (device.lowLightBoostEnabled) {
        NSLog(@"ENABLED");
    }

    // register as an observer of changes to lowLightBoostEnabled
    [device addObserver:self forKeyPath:@"automaticallyEnablesLowLightBoostWhenAvailable" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) context:NULL];

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {

    if ([keyPath isEqual:@"lowLightBoostEnabled"]) {

        NSLog(@"lowLightBoostEnabled changed");

        NSNumber *boostIsActiveValue = [change objectForKey:NSKeyValueChangeNewKey];

        BOOL boostIsActive = boostIsActiveValue.boolValue;

        NSLog(@"is low light boost currently active: %d", boostIsActive);
    }
}

谁能帮帮我?我在网上查过,但没有找到非常确凿的结果。我会很感激我能得到的所有帮助。

【问题讨论】:

    标签: ios objective-c avfoundation


    【解决方案1】:

    你需要lockForConfiguration,根据文档(嗯,头文件):

    if ([[self backFacingCamera] respondsToSelector:@selector(isLowLightBoostSupported)]) {
      if ([[self backFacingCamera] lockForConfiguration:nil]) {
        if ([self backFacingCamera].isLowLightBoostSupported)
          [self backFacingCamera].automaticallyEnablesLowLightBoostWhenAvailable = YES;
        [[self backFacingCamera] unlockForConfiguration];
      }
    }
    

    此外,isLowLightBoostEnabled 会告诉您是否确实增强了低光,而不是是否可以。这就是上面的 isLowLightBoostSupported 选择器(只有 iOS 6 设备才会响应)。

    【讨论】:

    • 谢谢,但我确实在代码中做到了这一点。它似乎没有用。还有其他建议吗?
    • 你说的是 iOS 6,所以我想在那个版本的 iOS 上,一些设备能够在低光下增强图像。问题是我使用的是新的 iPad Pro 7.9" 而isLowLightBoostSupported 给了我一个NO 你知道哪些设备可以做到这一点吗?谢谢。
    猜你喜欢
    • 2020-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多