2012-02-02 27 views
2

我想讓自動對焦在我的應用程序中工作,並在iPad2中進行測試。我的問題是,當我調用像isFocusModeSupported:AVCaptureFocusModeContinuousAutoFocus這樣的檢查方法時,它總是返回NO。不過,我可以在我的設備上點擊以關注其他相機應用程序AVFoundation焦點模式iPad2

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]; 
} 

回答

7

我今晚只是看着這個。從我所蒐集到的,iPad 2沒有做焦點 - 它確實曝光調整 - 所以在默認的相機應用程序,點擊屏幕會彈出一個矩形,其中點擊發生指示要做的區域白點調整

也許我錯了,但這是我已經出現的,似乎是由您的API(isFocusModeSupported:AVCaptureFocusModeContinuousAutoFocus返回NO)測試證實。

iPad 2中的攝像頭非常弱 - 尤其是前置攝像頭。我很驚訝蘋果出貨。

UPDATE:這是處理焦點+曝光+白點的更新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]; 
     } 
    }  
} 
} 
+0

那麼,如何應用程序顯示白色矩形,並有一定的影響改變 – vodkhang 2012-05-03 03:49:22

+0

看看在AVCam例子(還有另外一個,我覺得最近的'AVCamDemo'各地):http://developer.apple.com/library/ios/#samplecode/AVCam/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010112 – 2012-05-03 04:04:09

+0

我現在正在使用AVCam示例製作我自己的自定義界面。它包含測試isFocusPointOfInterestSupported的代碼。 我的iPad 2絕對會跳過這個。我相信'新'iPad會利用它。 – mpemburn 2012-05-07 21:18:36