有没有办法以编程方式将 iOS 设备的相机焦点设置为无限远?

发布于 2024-12-21 02:19:12 字数 67 浏览 1 评论 0原文

我正在创建一个应用程序,可以锁定相机焦点以进行视频录制。我想将焦点锁定到无限远,而无需用户手动调整焦点。这可能吗?谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

随心而道 2024-12-28 02:19:12

遗憾的是,没有。正如 Artem 所说,你可以将相机设置为焦点锁定模式;进入自动对焦模式(对焦,然后锁定)或连续自动对焦模式,但您无法为相机提供特定的对焦距离。

我能想到的最好的方法(对于曝光和白平衡控制,它们同样受到限制)是让用户将相机指向适当的场景(在您的情况下,是远处的场景)并让他/她按下锁定按钮。

有关捕获设备 API 的详细信息,例如:
https://developer.apple.com/library/mac/#文档/AVFoundation/Reference/AVCaptureDevice_Class/Reference/Reference.html

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

葬心 2024-12-28 02:19:12

这就是禁用焦点的方法,它会一直锁定焦点:

// 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");
    }

“将焦点锁定到无穷远”是什么意思?

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"?

笛声青案梦长安 2024-12-28 02:19:12

AVCaptureDevice 有函数 setFocusModeLockedWithLensPosition:completionHandler:

您可以使用它设置 1.0 以实现“无限”距离

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

更新:
根据Apple文档,1.0并不代表焦点在无限远。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文