我正在創建一個應用程序,用戶在該應用程序中使用文本拍攝圖片並上傳到服務器。我使用AVCaptureSession
來打開攝像頭並放置一個條形按鈕,它捕獲最新的幀並將其上傳到服務器。在這個應用程序中,用戶可以通過單擊條形圖按鈕,將多個圖像逐個發送到服務器。如何在iPhone SDK中自動對焦照片?
我想知道是否有可能用戶不必按下按鈕來捕捉框架。這是否有可能通過自動對焦自動捕捉當前幀?就像用戶只需將相機放在圖像上一秒鐘,當圖像聚焦時,它會自動捕獲,以便用戶可以移動到下一個圖像,而無需按任何按鈕?
我的代碼來捕獲框架如下:
- (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];
}
我將是你的幫助表示感謝。 謝謝。
你得到這個工作?只要標準在感興趣的區域實現,我需要自動捕獲圖像。所以,如果我正確理解這一點,我需要添加AVCaptureVideoDataOutput來接收相機信息,並使用adjustFocus觀察者來捕獲靜物圖像。你有什麼想法,我怎樣才能定義感興趣的區域(視圖的子部分),並忽略其餘的視圖? – Patricia 2014-09-04 17:26:28