我现在创建了相机应用程序,我想要做的是检查焦点是持续停止还是停止。
这就是我的尝试:
NSError *error=nil;
//Capture Session
AVCaptureSession *session = [[AVCaptureSession alloc]init];
session.sessionPreset = AVCaptureSessionPresetPhoto;
//Add device
AVCaptureDevice *device =
[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
// SETUP FOCUS MODE
if ([device lockForConfiguration:nil]) {
[device setFocusMode:AVCaptureFocusModeAutoFocus];
[device unlockForConfiguration];
}
else{
NSLog(@"error while configuring focusMode");
}
NSLog(@"%@" ,NSStringFromCGPoint(device.focusPointOfInterest));
if ([device isFocusModeSupported:AVCaptureFocusModeContinuousAutoFocus] && [device lockForConfiguration:&error]){
[device setFocusMode:AVCaptureFocusModeContinuousAutoFocus];
if ([device isFocusPointOfInterestSupported])
[device setFocusPointOfInterest:CGPointMake(0.5f,0.5f)];
[device unlockForConfiguration];
}
else{
NSLog(@"problem ");
}
//Input
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:nil];
if (!input)
{
NSLog(@"No Input");
}
[session addInput:input];
//Preview Layer
AVCaptureVideoPreviewLayer *previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
UIView *myView = viewForCamera;
previewLayer.frame = myView.bounds;
previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
[viewForCamera.layer addSublayer:previewLayer];
//Start capture session
[session startRunning];
我搜索的是有任何委托方法,但我没有得到,请帮我解决这个问题。
答案 0 :(得分:2)
我得到了解决方案。我尝试了样本。我用谷歌搜索并经历了很多答案。
我们必须在调用setFocusMode
之前设置兴趣点
在您的编码中,您尚未调用兴趣点
if ([device isFocusPointOfInterestSupported])
{
[device setFocusPointOfInterest:CGPointMake(0.5f,0.5f)];
[device setFocusMode:AVCaptureFocusModeAutoFocus];
//OR
[device setFocusMode:AVCaptureFocusModeContinuousAutoFocus];
[device unlockForConfiguration];
}
然后查找自动对焦是否正常