Wie mache ich ein Foto automatisch im Fokus im iPhone SDK?

Ich erstelle eine App, in der der Benutzer ein Bild mit Text aufnimmt und auf den Server hochlädt. Ich habe benutztAVCaptureSession um die Kamera zu öffnen und einen Balkenknopf zu platzieren, der das neueste Bild aufnimmt und es auf den Server hochlädt. In dieser App kann der Benutzer mehrere Bilder nacheinander an den Server senden, indem er auf die Leistenschaltfläche klickt.

Ich habe mich gefragt, ob es möglich ist, dass der Benutzer nicht die Taste drücken muss, um ein Bild aufzunehmen. Ist es möglich, dass das aktuelle Bild automatisch mit Autofokus aufgenommen wird? Als ob der Benutzer die Kamera nur für eine Sekunde auf dem Bild platziert und wenn das Bild gut fokussiert ist, wird es automatisch erfasst, so dass der Benutzer zum nächsten Bild wechseln kann, ohne eine Taste drücken zu müssen?

Mein Code zum Erfassen des Frames lautet wie folgt:

- (void)initCapture {

    AVCaptureDeviceInput *captureInput = [AVCaptureDeviceInput 
                                          deviceInputWithDevice:[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo] 
                                          error:nil];

    AVCaptureVideoDataOutput *captureOutput = [[AVCaptureVideoDataOutput alloc] init];

    captureOutput.alwaysDiscardsLateVideoFrames = YES; 







    /*We create a serial queue to handle the processing of our frames*/
    dispatch_queue_t queue;
    queue = dispatch_queue_create("cameraQueue", NULL);
    [captureOutput setSampleBufferDelegate:self queue:queue];
    dispatch_release(queue);
    // Set the video output to store frame in BGRA (It is supposed to be faster)
    NSString* key = (NSString*)kCVPixelBufferPixelFormatTypeKey; 
    NSNumber* value = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA]; 
    NSDictionary* videoSettings = [NSDictionary dictionaryWithObject:value forKey:key]; 
    [captureOutput setVideoSettings:videoSettings]; 
    /*And we create a capture session*/
    captureSession = [[AVCaptureSession alloc] init];
    /*We add input and output*/
    [captureSession addInput:captureInput];
    [captureSession addOutput:captureOutput];





    AVCaptureConnection *conn = [captureOutput connectionWithMediaType:AVMediaTypeVideo];

    if (conn.supportsVideoMinFrameDuration)
        conn.videoMinFrameDuration = CMTimeMake(5,1);
    if (conn.supportsVideoMaxFrameDuration)
        conn.videoMaxFrameDuration = CMTimeMake(5,1);





    [captureSession setSessionPreset:AVCaptureSessionPresetPhoto];

    customLayer = [CALayer layer];
    customLayer.frame = self.view.bounds;
    customLayer.transform = CATransform3DRotate(CATransform3DIdentity, M_PI/2.0f, 0, 0, 1);
    customLayer.contentsGravity = kCAGravityResizeAspectFill;
    //[self.view.layer addSublayer:customLayer];
    /*We add the imageView*/



    imageView = [[UIImageView alloc] init];
    imageView.frame = CGRectMake(0, 0, 100, 100);
    //imageView.frame = self.view.bounds;
    [self.view addSubview:imageView];



    [captureSession startRunning];

}

Ich werde für Ihre Hilfe dankbar sein. Vielen Dank.

Antworten auf die Frage(1)

Ihre Antwort auf die Frage