0

iOS 6 を搭載した iPad 3 でカメラを起動すると、カメラはフォーカス操作を行います。これは、私が AVFoundation フレームワークで行っている方法です:\

//
// AppDelegate.h
//

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;


@property (strong, nonatomic) AVCaptureSession *session;
@property (strong, nonatomic) AVCaptureVideoPreviewLayer *captureVideoPreviewLayer;
@property (strong, nonatomic) AVCaptureDevice *device;
@property (strong, nonatomic) AVCaptureDeviceInput *input;
@property(nonatomic, strong) AVCaptureStillImageOutput *stillImageOutput;

@end

//
//  AppDelegate.m
//


@implementation AppDelegate
@synthesize session;
@synthesize captureVideoPreviewLayer;
@synthesize device;
@synthesize input;
@synthesize stillImageOutput;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{    
    device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    NSError *error = nil;

    if (([device hasMediaType:AVMediaTypeVideo]) &&
        ([device position] == AVCaptureDevicePositionBack) ) {
        [device lockForConfiguration:&error];
        if ([device isFocusModeSupported:AVCaptureFocusModeLocked]) {
            device.focusMode = AVCaptureFocusModeLocked;
            NSLog(@"Focus locked");
        }

        [device unlockForConfiguration];
    }

    session = [[AVCaptureSession alloc] init];
    session.sessionPreset = AVCaptureSessionPresetPhoto;

    captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
    [captureVideoPreviewLayer setAffineTransform:CGAffineTransformMakeRotation(-M_PI / 2)];


    input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
    if (!input) {
        // Handle the error appropriately.
        NSLog(@"ERROR: trying to open camera: %@", error);
    }
    [session addInput:input];

    stillImageOutput = [[AVCaptureStillImageOutput alloc] init];

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

    [session addOutput:stillImageOutput];
    [session startRunning];

    return YES;
}

AVDevice具体的には起動時( )にフォーカスをロックしているのですdevice.focusMode = AVCaptureFocusModeLocked;が、カメラ起動時にフォーカス操作を行ってしまいます。私のアプリケーションでは、カメラのキャリブレーションのために、これが発生したくありません。

カメラの初期化時にフォーカスが発生しないようにするにはどうすればよいですか?

4

1 に答える 1