我正在尝试在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];
}
最佳答案
我只是今晚在调查。从我收集到的信息来看,iPad 2不会对焦-会进行曝光调整-因此在默认的“相机”应用中,点击屏幕会在出现点击的地方显示一个矩形,指示要进行白点调整的区域。
也许我错了,但这就是我所发现的,并且似乎已通过您的API(isFocusModeSupported:AVCaptureFocusModeContinuousAutoFocus
返回NO)测试得到了证实。
iPad 2中的相机非常薄弱-尤其是前置相机。令苹果感到惊讶的是我。
更新:这是来自更新的Apple的AVCamDemo示例的代码,该示例处理焦点+曝光+白点。我不认为这是在AVCam示例中。 AVCamDemo可能只能从开发人员中心下载WWDC代码.dmg软件包,而不能从Web上一次下载。
在我的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];
}
}
}
}
关于iphone - AVFoundation对焦模式iPad2,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9107773/