获取iOS设备的焦距 [英] Get focal length of iOS devices

查看:222
本文介绍了获取iOS设备的焦距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Swift中,有没有一种简单的方法可以找到当前使用的相机的焦距? 我正在使用iOS应用程序,并且需要使用iOS相机的焦距(以像素或毫米为单位).我从Apple找到了有关焦距的文档,但是没有有关如何获取焦距的信息.这是我去过的两个地方:

In Swift, is there an easy way to find the focal length of the currently using camera? I am working on an iOS application and I need to use the focal length (in pixels or in mm) of iOS cameras. I found documentation from Apple about the focal length, but there is no information about how to obtain it. Here are two places I have visited:

  • mdlcamera
  • coreimage

我还检查了

I have also checked this question but it doesn't seem to solve my problem. I know that the focal length can be calculated using the Field of View as follows:

focal_length_pixels = (image_diagonal_pixels/2)/tan(FOV/2)

但同样,在计算该数量方面没有任何指导.

but again, there are no guides in computing that quantity.

能请你帮忙吗? 谢谢.

Could you please help? Thanks.

推荐答案

此功能适用于像我之前遇到过相同问题的人.基本上,我们需要拍照,然后使用捕获的图片检测焦距:

This function is for those who have the same problem like me before. Basically, we'll have to take a picture, then use the captured picture to detect the focal length:

    // delegate method for the image picker
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

        let metadata = info[UIImagePickerControllerMediaMetadata] as? NSDictionary
        let exifdata = metadata!["{Exif}"] as! NSDictionary

        // focal length
        let focalLength = exifdata["FocalLength"] as! Double

        print("Focal length \(focalLength)")
    }

这篇关于获取iOS设备的焦距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆