Is there any way to programmatically set the camera focus off an iOS device to infinity?

送分小仙女□ 提交于 2019-12-03 11:58:16

问题


I am creating an app that locks the camera focus for video recording purposes. I want to lock the focus to infinity without having the user manually adjust the focus. Is this possible? Thanks!


回答1:


That is the way to disable focus, it locks it for all the time:

// Find a suitable capture device
    AVCaptureDevice *cameraDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

    // SETUP FOCUS MODE
    if ([cameraDevice lockForConfiguration:nil]) {

        [cameraDevice setFocusMode:AVCaptureFocusModeLocked];

        [cameraDevice unlockForConfiguration];
    }
    else{
        NSLog(@"error while configuring focusMode");
    }

What do you mean "lock the focus to infinity"?




回答2:


Sadly, no. You can set the camera into focus-locked mode, as Artem said; put into autofocus mode (focus, then lock), or continuous autofocus mode, but you can't give the camera a specific distance to focus at.

The best I've been able to come up with (for exposure and white balance control, which are similarly limited) is to have the user point the camera at an appropriate scene (in your case, something far away) and have him/her push a lock button.

Details on the capture device API, such as it is: https://developer.apple.com/library/mac/#documentation/AVFoundation/Reference/AVCaptureDevice_Class/Reference/Reference.html




回答3:


AVCaptureDevice has function setFocusModeLockedWithLensPosition:completionHandler:

You can use it to set 1.0 in order to achieve "infinity" distance

    func focusTo(value : Float) {
      if let device = captureDevice {
      if(device.lockForConfiguration(nil)) {
         device.setFocusModeLockedWithLensPosition(value, completionHandler: { (time) -> Void in
            //
        })
        device.unlockForConfiguration()
      }
    }

Update: According to Apple documentation 1.0 does not represent focus at infinity.



来源:https://stackoverflow.com/questions/8488736/is-there-any-way-to-programmatically-set-the-camera-focus-off-an-ios-device-to-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!