AVFoundation对焦模式iPad2

时间:2012-02-02 05:53:17

标签: iphone objective-c ipad avfoundation autofocus

我正在尝试在我的应用中进行自动对焦,在iPad2中进行测试。我的问题是,当我调用isFocusModeSupported:AVCaptureFocusModeContinuousAutoFocus等检查方法时,它总是返回NO。但是,我可以点击以关注我设备中的其他相机应用程序

devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
for (AVCaptureDevice *tempDevice in devices) {
    [tempDevice lockForConfiguration:nil];
    if ([tempDevice isFocusModeSupported:AVCaptureFocusModeAutoFocus]) {
        NSLog(@"Here");
    }

    if ([tempDevice isFocusModeSupported:AVCaptureFocusModeContinuousAutoFocus]) {
        NSLog(@"Here");
    }

    if ([tempDevice isFocusModeSupported:AVCaptureFocusModeLocked]) {
        NSLog(@"Here");
    }

    if ([tempDevice isFocusPointOfInterestSupported]) {
        NSLog(@"Here");
    }
    [tempDevice unlockForConfiguration];
}

1 个答案:

答案 0 :(得分:7)

我今晚只是在考虑这个问题。从我收集的内容来看,iPad 2并没有聚焦 - 它会进行曝光调整 - 所以在默认的相机应用程序中,点击屏幕会显示一个矩形点击发生的位置表示要进行白点调整的区域。

也许我错了,但这就是我所提出的,似乎已经通过您的API(isFocusModeSupported:AVCaptureFocusModeContinuousAutoFocus返回NO)测试得到了证实。

iPad 2中的相机非常弱 - 尤其是前置相机。我很惊讶苹果发货了。

更新:这是最近处理焦点+曝光+白点的AVCamDemo Apple示例中的代码。我不认为这是在AVCam示例中。 AVCamDemo可以从开发人员中心下载WWDC代码.dmg软件包,而不是从网上下载。  在我的iPad 2上,曝光代码永远不会被调用。 // - 来自AVCamDemo:

- (BOOL) hasExposure
 {
AVCaptureDevice *device = [[self videoInput] device];

return  [device isExposureModeSupported:AVCaptureExposureModeLocked] ||
        [device isExposureModeSupported:AVCaptureExposureModeAutoExpose] ||
        [device isExposureModeSupported:AVCaptureExposureModeContinuousAutoExposure];
}

- (AVCaptureExposureMode) exposureMode
{
return [[[self videoInput] device] exposureMode];
}

- (void) setExposureMode:(AVCaptureExposureMode)exposureMode
{
if (exposureMode == 1) {
    exposureMode = 2;
}
AVCaptureDevice *device = [[self videoInput] device];
if ([device isExposureModeSupported:exposureMode] && [device exposureMode] != exposureMode) {
    NSError *error;
    if ([device lockForConfiguration:&error]) {
        [device setExposureMode:exposureMode];
        [device unlockForConfiguration];
    } else {
        id delegate = [self delegate];
        if ([delegate respondsToSelector:@selector(acquiringDeviceLockFailedWithError:)]) {
            [delegate acquiringDeviceLockFailedWithError:error];
        }
    }
}
}

- (BOOL) hasWhiteBalance
{
AVCaptureDevice *device = [[self videoInput] device];

return  [device isWhiteBalanceModeSupported:AVCaptureWhiteBalanceModeLocked] ||
        [device isWhiteBalanceModeSupported:AVCaptureWhiteBalanceModeAutoWhiteBalance];
}

- (AVCaptureWhiteBalanceMode) whiteBalanceMode
{
return [[[self videoInput] device] whiteBalanceMode];
}

- (void) setWhiteBalanceMode:(AVCaptureWhiteBalanceMode)whiteBalanceMode
{
if (whiteBalanceMode == 1) {
    whiteBalanceMode = 2;
}    
AVCaptureDevice *device = [[self videoInput] device];
if ([device isWhiteBalanceModeSupported:whiteBalanceMode] && [device whiteBalanceMode] != whiteBalanceMode) {
    NSError *error;
    if ([device lockForConfiguration:&error]) {
        [device setWhiteBalanceMode:whiteBalanceMode];
        [device unlockForConfiguration];
    } else {
        id delegate = [self delegate];
        if ([delegate respondsToSelector:@selector(acquiringDeviceLockFailedWithError:)]) {
            [delegate acquiringDeviceLockFailedWithError:error];
        }
    }
}
}

- (BOOL) hasFocus
{
AVCaptureDevice *device = [[self videoInput] device];

return  [device isFocusModeSupported:AVCaptureFocusModeLocked] ||
        [device isFocusModeSupported:AVCaptureFocusModeAutoFocus] ||
        [device isFocusModeSupported:AVCaptureFocusModeContinuousAutoFocus];
}

- (AVCaptureFocusMode) focusMode
{
return [[[self videoInput] device] focusMode];
}

- (void) setFocusMode:(AVCaptureFocusMode)focusMode
{


AVCaptureDevice *device = [[self videoInput] device];
if ([device isFocusModeSupported:focusMode] && [device focusMode] != focusMode) {
    NSError *error;

      printf(" setFocusMode    \n");
    if ([device lockForConfiguration:&error]) {
        [device setFocusMode:focusMode];
        [device unlockForConfiguration];
    } else {
        id delegate = [self delegate];
        if ([delegate respondsToSelector:@selector(acquiringDeviceLockFailedWithError:)]) {
            [delegate acquiringDeviceLockFailedWithError:error];
        }
    }    
}
}