如何使用图像Exif元数据从iPhone相机获取目标距离?

时间:2022-09-23 09:46:46

Edit: Sorry for late Edit, Without two parameter you cannot calculate it, So first need to fill user Camera height from ground.

编辑:抱歉后期编辑,没有两个参数你无法计算,所以首先需要从地面填充用户相机高度。


I have check a number of solutions but none of them helpful!

我检查了一些解决方案,但没有一个是有用的!

I know that Working Distance = (Sensor Height + Subject Height) * Focal Length / Sensor Height

我知道工作距离=(传感器高度+受试者高度)*焦距/传感器高度

and

distance to object (mm) = focal length (mm) * real height of the object (mm) * image height (pixels)
                          ----------------------------------------------------------------
                                object height (pixels) * sensor height (mm)

And I want to get distance from this:

我想和这个保持距离

Image Formation by Lenses and the Eye

通过透镜和眼睛形成图像

Hello I get the following info using image Exif ALAssetsLibrary

你好,我得到以下信息使用图片Exif ALAssetsLibrary

And I got following meta data :

我得到了以下元数据:

Save image metadata.
 {
    DPIHeight = 72;
    DPIWidth = 72;
    FaceRegions =     {
        Regions =         {
            HeightAppliedTo = 2448;
            RegionList =             (
                                {
                    AngleInfoRoll = 270;
                    AngleInfoYaw = 0;
                    ConfidenceLevel = 376;
                    FaceID = 1;
                    Height = "0.1413399";
                    Timestamp = 5996166864910;
                    Type = Face;
                    Width = "0.1060049";
                    X = "0.3560049";
                    Y = "0.4746732";
                }
            );
            WidthAppliedTo = 3264;
        };
    };
    Orientation = 6;
    "{Exif}" =     {
        ApertureValue = "2.526068811667587";
        BrightnessValue = "1.291629806962232";
        ColorSpace = 1;
        DateTimeDigitized = "2014:03:25 15:43:36";
        DateTimeOriginal = "2014:03:25 15:43:36";
        ExposureMode = 0;
        ExposureProgram = 2;
        ExposureTime = "0.05";
        FNumber = "2.4";
        Flash = 24;
        FocalLenIn35mmFilm = 33;
        FocalLength = "4.12";
        ISOSpeedRatings =         (
            160
        );
        LensMake = Apple;
        LensModel = "iPhone 5 back camera 4.12mm f/2.4";
        LensSpecification =         (
            "4.12",
            "4.12",
            "2.4",
            "2.4"
        );
        MeteringMode = 5;
        PixelXDimension = 3264;
        PixelYDimension = 2448;
        SceneType = 1;
        SensingMethod = 2;
        ShutterSpeedValue = "4.321956949076723";
        SubjectArea =         (
            1631,
            1223,
            1795,
            1077
        );
        SubsecTimeDigitized = 261;
        SubsecTimeOriginal = 261;
        UserComment = hoge;
        WhiteBalance = 0;
    };
    "{GPS}" =     {
        Altitude = "196.008";
        AltitudeRef = 0;
        DateStamp = "2014:03:25";
        Latitude = "28.61772";
        LatitudeRef = N;
        Longitude = "77.38891";
        LongitudeRef = E;
        TimeStamp = "10:13:37.439000";
    };
    "{MakerApple}" =     {
        1 = 0;
        3 =         {
            epoch = 0;
            flags = 1;
            timescale = 1000000000;
            value = 249840592070541;
        };
        4 = 0;
        5 = 179;
        6 = 139;
        7 = 1;
    };
    "{TIFF}" =     {
        DateTime = "2014:03:25 15:43:36";
        Make = Apple;
        Model = "iPhone 5";
        Software = "7.0.6";
        XResolution = 72;
        YResolution = 72;
    };
}

I need to calculate the distance of the object from the camera, using the above details; using iphone4s,iphone5, or iphone5s. Is it possible?

我需要用上面的细节来计算物体距离摄像机的距离;使用iphone4s,iphone5,或者iphone5。是可能的吗?

如何使用图像Exif元数据从iPhone相机获取目标距离?

Modified Need to know formula used by this app any idea:

修改后需要了解本应用使用的公式任何想法:

Need to know any method

需要知道任何方法

http://www.youtube.com/watch?v=eCStIagorx8

http://www.youtube.com/watch?v=eCStIagorx8

how this App working ??? All Help are welcome

这个应用程序是如何工作的?所有的帮助都是受欢迎的

4 个解决方案

#1


14  

@iphonemaclover. As many people have pointed out there's insufficient information to calculate this purely using trigonometry. However, depending on how accurate you need to be, or what it is you're trying to measure and other data you can expect to recover from an iphone and/or you're willing to make some assumptions, it is possible to make some inroads.

@iphonemaclover。正如许多人指出的那样,单纯用三角函数来计算是不够的。然而,根据你需要的精确程度,或者你想要测量的是什么以及你希望从iphone中恢复的其他数据,或者你愿意做一些假设,有可能取得一些进展。

a) +1 to Martin R, if you assume a flat earth, a phone height (which as per the app you quoted) a user could update for calibration purposes, can recover pitch information and know where a point on the ground at the base of your object is then this is simple trig. Once there's a estimate for the distance and assuming the thing you're measuring is close to vertical (or sits at a known angle) then its height can also be calculated.

马丁R)+ 1,如果你认为一个平坦的地球,一个电话高度(按你报的应用程序)的用户可以更新校准的目的,可以恢复场地信息,知道一个点在地面上物体的底部是这是简单的三角。一旦有了距离的估计,假设你测量的东西接近垂直(或者是已知的角度),那么它的高度也可以计算出来。

b) Your exif file contains face region information. If you're interested in people and are happy to make an assumption that they're an adult then you could use an average head size assumption to estimate distance using the method you've outlined already.

b)您的exif文件包含了face region信息。如果你对人感兴趣,并且乐于假设他们是成年人,那么你可以使用一个平均的头部尺寸假设来估算距离使用你已经概述过的方法。

c) If you can recover a series of images and camera positions and the camera / object positions vary then I believe that 3d information can be recovered using projective geometry.

c)如果你可以恢复一系列的图像和相机的位置,并且相机/对象的位置不同,那么我相信3d信息可以通过投影几何来恢复。

#2


9  

If you're wondering how to find distance given the phone/tablet height and pitch up/downward, just use the atan of the angle downwards (0 if it is pointed forward; -30 if it is -30 degrees downwards) times the height.The only problem is, we don't know the phone height off the ground.

如果你想知道如何在手机/平板电脑的高度上找到距离,并且俯仰/向下,只要用角度向下的atan就可以了;-30如果它是-30度向下)乘以高度。唯一的问题是,我们不知道地面上的电话高度。

I know you want to use the focus of the camera, but that is improbable. You mentioned an android app, while if you'll notice that app requires you to enter phone height off the ground. You could try using GPS altitude minus what a topographic map says, but that is incredibly inaccurate. Or maybe you could take a picture from one location, then move around the target by 45 degrees or so, but not everyone has a compass to measure that or has the ability to run circles around the target. How would you move 45 degrees around a object in front of you while standing on a bridge? Even if you did try to use the camera focus, that is automatically updated and I know nothing about using a variable to find the camera focus. https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/04_MediaCapture.html shows how to set focus mode, but I can't find anything on setting a custom focus or viewing what the camera is focused on. If you want to take a picture and do some sort of custom pixel by pixel analysis to see how it's focused, by all means go ahead. Maybe a jail-broken iPhone can access camera focus, but I'm guessing that your target audience is more then the select group that have gone through the jail-breaking process.

我知道你想用相机的焦点,但那是不可能的。你提到了一个android应用,如果你注意到这个应用要求你在地上输入手机高度。你可以试着用GPS高度减去地形图上说的,但这是非常不准确的。或者你可以从一个位置拍一张照片,然后在目标周围移动45度左右,但不是每个人都有一个指南针来测量或者有能力绕着目标运行。当你站在桥上时,你如何在你面前移动45度的物体?即使你尝试使用相机焦点,它会自动更新,我也不知道如何使用一个变量来找到相机焦点。html显示了如何设置焦点模式,但我找不到任何设置自定义焦点或查看相机所关注的内容的内容。如果你想拍张照片,通过像素分析来做一些自定义像素,看看它是如何聚焦的,那就一定要去做。也许一个破解版的iPhone可以访问相机焦点,但我猜你的目标受众比经过破解过程的选择组要多。

I think the easiest way to find the height is to have them point their phone down at their foot. Then you can ask them shoe size and brand to estimate the width of their shoe, or just make a flat out guess. Just ask them to point at the side of their shoe, perhaps by displaying a red dot in the middle of the screen so they know exactly where they're pointing. Then ask them to point at the other and then, once you have captured both edges of their shoe, use the estimated inch width of their shoe multiplied by the tan of the angle difference from one edge to the other (so if it is 170 degrees when pointed at one edge and 190 when at the other use the tan of 20). That should give you the height in inches off the ground.

我认为找到身高最简单的方法就是让他们把手机放在脚边。然后你可以问他们鞋的尺寸和品牌来估计他们的鞋的宽度,或者仅仅做一个粗略的猜测。让他们指着鞋子的一边,也许在屏幕中间显示一个红点,这样他们就知道自己指向哪里了。然后问他们点其他,一旦你有了两个边缘的鞋,用鞋的估计英寸宽度乘以这个角的正切差异从一边到另一(如果它是170度当指着一个边缘和190年20)的其他使用棕褐色。这应该是离地面几英寸的高度。

    s = shoe width;
    ao = angle when pointed at left shoe edge (y-axis)(radians);
    at = angle when pointed at right shoe edge (y-axis)(radians);
    a = angle of device when pointed at the point on the ground (x-axis)(radians);
    d = distance;
    d = atan(a) * tan(at - ao) * s;

#3


5  

Its not possible way to get distance while varying ground-mobile distance dynamically from each person. Manually user have to set the height of the mobile each time to calculate.

这是一种不可能的方法来获得距离,同时动态地改变与每个人的地面移动距离。手动用户每次都要设置手机的高度来计算。

#4


2  

I know this is an old question, but something had me thinking about whether it was possible to use an iPhone's focus sensor to measure distance to an object, and this came up in my searches.

我知道这是个老问题,但有件事让我思考,用iPhone的焦点传感器来测量物体的距离是否可能,我在搜索时遇到了这个问题。

I think that in @iphonemaclover's original question, the "sensor height" does not refer to the camera's height above the ground, but the physical height of the camera sensor inside the phone. After all, if you had the phone on a rotating arm pivoting around the subject, the distance to the subject could remain constant while the phone's vertical position changed. It's the sensor size and focal length that determine what is in its frame.

我认为在@iphonemaclover的原始问题中,“传感器高度”并不是指相机在地面上方的高度,而是指手机内摄像机传感器的物理高度。毕竟,如果你把手机放在转动的手臂上绕着被摄物旋转,当手机的垂直位置发生变化时,与被摄物的距离可以保持不变。是传感器的大小和焦距决定了它的框架。

With that in mind, I did some quick experiments with my phone which seemed to bear this out (though, I'll admit that I did not perform any real measurements beyond eyeball estimates and a desk ruler.)

考虑到这一点,我用我的手机做了一些快速的实验,似乎证明了这一点(不过,我得承认,除了目镜估计和台尺之外,我并没有进行任何真正的测量)。

I was using an iPhone 5, and with a little Googling, we can learn some key pieces of information about its camera sensor:

我用的是iPhone 5,用谷歌搜索一下,我们就能了解到它的相机传感器的一些关键信息:

  • pixel resolution: 3264 x 2448
  • 像素分辨率:3264 x 2448
  • focal length: 4.10mm
  • 焦距:4.10毫米
  • sensor size: 4.54 x 3.42 mm
  • 传感器尺寸:4.54 x 3.42 mm

So: the first formula above for "Working Distance" can tell us the distance at which a subject of a given size will fill the sensor's frame. With the camera in landscape orientation, and a subject 2m tall (2000mm), we get:

所以:“工作距离”上面的第一个公式可以告诉我们一个给定大小的物体将填满传感器框架的距离。有了相机的景观朝向,和一个2米高(2000毫米)的主体,我们得到:

(3.42 + 2000) * 4.10
--------------------  =  2401.76mm, or about 2.4m
        3.42

So if you stand about 2.4m away from a 2m tall person, they should fill the frame in landscape orientation. For portrait, you'll need to step up to about 1.8m away.

因此,如果你站在距离2米高的人2.4米的地方,他们应该在景观的方向上填充框架。对于人像,你需要走到大约1.8米远。

That's all fine and wonderful for filling the frame. But we want to calculate for arbitrary distances, by seeing how much of the frame our subject takes up. That's what the second formula is for. Let's again use our 2m tall subject, and plug numbers in. For this experiment, let's say that we've examined our image, and the subject in the photo is taking up 1800 pixels, vertically. Plugging into the second distance formula, we get:

这对填充框架来说是很好的。但是我们想要计算任意距离,通过观察主体所占的帧数。这就是第二个公式的作用。我们再用2米高的题目,代入数字。在这个实验中,假设我们已经检查了我们的图像,照片中的主体垂直于1800像素。代入第二个距离公式,我们得到:

4.10 * 2000 * 2448
------------------  =  3260.82mm, or ~ 3.26m
    1800 * 3.42

And if the subject took up the same 1800 vertical pixels in portrait mode, then we could guess that the photographer was about 3.28m away.

如果被试在人像模式中占据了相同的1800个垂直像素,那么我们可以猜测摄影师在3.28米之外。

This all assumes that the formulae given above are correct. And again, I only did rudimentary attempts at verifying the 'full-frame' measurements (once with a subject about 28cm tall, then with a subject about 1.7m tall). But my eyeball estimates looked reasonably close to what the formula predicted.

这一切都假定上述公式是正确的。而且,我只做了一些初步的尝试来验证“全框架”的测量(曾经有一个大约28厘米高的物体,然后是一个大约1.7米高的物体)。但我的眼球估计值看起来相当接近公式的预测。

#1


14  

@iphonemaclover. As many people have pointed out there's insufficient information to calculate this purely using trigonometry. However, depending on how accurate you need to be, or what it is you're trying to measure and other data you can expect to recover from an iphone and/or you're willing to make some assumptions, it is possible to make some inroads.

@iphonemaclover。正如许多人指出的那样,单纯用三角函数来计算是不够的。然而,根据你需要的精确程度,或者你想要测量的是什么以及你希望从iphone中恢复的其他数据,或者你愿意做一些假设,有可能取得一些进展。

a) +1 to Martin R, if you assume a flat earth, a phone height (which as per the app you quoted) a user could update for calibration purposes, can recover pitch information and know where a point on the ground at the base of your object is then this is simple trig. Once there's a estimate for the distance and assuming the thing you're measuring is close to vertical (or sits at a known angle) then its height can also be calculated.

马丁R)+ 1,如果你认为一个平坦的地球,一个电话高度(按你报的应用程序)的用户可以更新校准的目的,可以恢复场地信息,知道一个点在地面上物体的底部是这是简单的三角。一旦有了距离的估计,假设你测量的东西接近垂直(或者是已知的角度),那么它的高度也可以计算出来。

b) Your exif file contains face region information. If you're interested in people and are happy to make an assumption that they're an adult then you could use an average head size assumption to estimate distance using the method you've outlined already.

b)您的exif文件包含了face region信息。如果你对人感兴趣,并且乐于假设他们是成年人,那么你可以使用一个平均的头部尺寸假设来估算距离使用你已经概述过的方法。

c) If you can recover a series of images and camera positions and the camera / object positions vary then I believe that 3d information can be recovered using projective geometry.

c)如果你可以恢复一系列的图像和相机的位置,并且相机/对象的位置不同,那么我相信3d信息可以通过投影几何来恢复。

#2


9  

If you're wondering how to find distance given the phone/tablet height and pitch up/downward, just use the atan of the angle downwards (0 if it is pointed forward; -30 if it is -30 degrees downwards) times the height.The only problem is, we don't know the phone height off the ground.

如果你想知道如何在手机/平板电脑的高度上找到距离,并且俯仰/向下,只要用角度向下的atan就可以了;-30如果它是-30度向下)乘以高度。唯一的问题是,我们不知道地面上的电话高度。

I know you want to use the focus of the camera, but that is improbable. You mentioned an android app, while if you'll notice that app requires you to enter phone height off the ground. You could try using GPS altitude minus what a topographic map says, but that is incredibly inaccurate. Or maybe you could take a picture from one location, then move around the target by 45 degrees or so, but not everyone has a compass to measure that or has the ability to run circles around the target. How would you move 45 degrees around a object in front of you while standing on a bridge? Even if you did try to use the camera focus, that is automatically updated and I know nothing about using a variable to find the camera focus. https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/04_MediaCapture.html shows how to set focus mode, but I can't find anything on setting a custom focus or viewing what the camera is focused on. If you want to take a picture and do some sort of custom pixel by pixel analysis to see how it's focused, by all means go ahead. Maybe a jail-broken iPhone can access camera focus, but I'm guessing that your target audience is more then the select group that have gone through the jail-breaking process.

我知道你想用相机的焦点,但那是不可能的。你提到了一个android应用,如果你注意到这个应用要求你在地上输入手机高度。你可以试着用GPS高度减去地形图上说的,但这是非常不准确的。或者你可以从一个位置拍一张照片,然后在目标周围移动45度左右,但不是每个人都有一个指南针来测量或者有能力绕着目标运行。当你站在桥上时,你如何在你面前移动45度的物体?即使你尝试使用相机焦点,它会自动更新,我也不知道如何使用一个变量来找到相机焦点。html显示了如何设置焦点模式,但我找不到任何设置自定义焦点或查看相机所关注的内容的内容。如果你想拍张照片,通过像素分析来做一些自定义像素,看看它是如何聚焦的,那就一定要去做。也许一个破解版的iPhone可以访问相机焦点,但我猜你的目标受众比经过破解过程的选择组要多。

I think the easiest way to find the height is to have them point their phone down at their foot. Then you can ask them shoe size and brand to estimate the width of their shoe, or just make a flat out guess. Just ask them to point at the side of their shoe, perhaps by displaying a red dot in the middle of the screen so they know exactly where they're pointing. Then ask them to point at the other and then, once you have captured both edges of their shoe, use the estimated inch width of their shoe multiplied by the tan of the angle difference from one edge to the other (so if it is 170 degrees when pointed at one edge and 190 when at the other use the tan of 20). That should give you the height in inches off the ground.

我认为找到身高最简单的方法就是让他们把手机放在脚边。然后你可以问他们鞋的尺寸和品牌来估计他们的鞋的宽度,或者仅仅做一个粗略的猜测。让他们指着鞋子的一边,也许在屏幕中间显示一个红点,这样他们就知道自己指向哪里了。然后问他们点其他,一旦你有了两个边缘的鞋,用鞋的估计英寸宽度乘以这个角的正切差异从一边到另一(如果它是170度当指着一个边缘和190年20)的其他使用棕褐色。这应该是离地面几英寸的高度。

    s = shoe width;
    ao = angle when pointed at left shoe edge (y-axis)(radians);
    at = angle when pointed at right shoe edge (y-axis)(radians);
    a = angle of device when pointed at the point on the ground (x-axis)(radians);
    d = distance;
    d = atan(a) * tan(at - ao) * s;

#3


5  

Its not possible way to get distance while varying ground-mobile distance dynamically from each person. Manually user have to set the height of the mobile each time to calculate.

这是一种不可能的方法来获得距离,同时动态地改变与每个人的地面移动距离。手动用户每次都要设置手机的高度来计算。

#4


2  

I know this is an old question, but something had me thinking about whether it was possible to use an iPhone's focus sensor to measure distance to an object, and this came up in my searches.

我知道这是个老问题,但有件事让我思考,用iPhone的焦点传感器来测量物体的距离是否可能,我在搜索时遇到了这个问题。

I think that in @iphonemaclover's original question, the "sensor height" does not refer to the camera's height above the ground, but the physical height of the camera sensor inside the phone. After all, if you had the phone on a rotating arm pivoting around the subject, the distance to the subject could remain constant while the phone's vertical position changed. It's the sensor size and focal length that determine what is in its frame.

我认为在@iphonemaclover的原始问题中,“传感器高度”并不是指相机在地面上方的高度,而是指手机内摄像机传感器的物理高度。毕竟,如果你把手机放在转动的手臂上绕着被摄物旋转,当手机的垂直位置发生变化时,与被摄物的距离可以保持不变。是传感器的大小和焦距决定了它的框架。

With that in mind, I did some quick experiments with my phone which seemed to bear this out (though, I'll admit that I did not perform any real measurements beyond eyeball estimates and a desk ruler.)

考虑到这一点,我用我的手机做了一些快速的实验,似乎证明了这一点(不过,我得承认,除了目镜估计和台尺之外,我并没有进行任何真正的测量)。

I was using an iPhone 5, and with a little Googling, we can learn some key pieces of information about its camera sensor:

我用的是iPhone 5,用谷歌搜索一下,我们就能了解到它的相机传感器的一些关键信息:

  • pixel resolution: 3264 x 2448
  • 像素分辨率:3264 x 2448
  • focal length: 4.10mm
  • 焦距:4.10毫米
  • sensor size: 4.54 x 3.42 mm
  • 传感器尺寸:4.54 x 3.42 mm

So: the first formula above for "Working Distance" can tell us the distance at which a subject of a given size will fill the sensor's frame. With the camera in landscape orientation, and a subject 2m tall (2000mm), we get:

所以:“工作距离”上面的第一个公式可以告诉我们一个给定大小的物体将填满传感器框架的距离。有了相机的景观朝向,和一个2米高(2000毫米)的主体,我们得到:

(3.42 + 2000) * 4.10
--------------------  =  2401.76mm, or about 2.4m
        3.42

So if you stand about 2.4m away from a 2m tall person, they should fill the frame in landscape orientation. For portrait, you'll need to step up to about 1.8m away.

因此,如果你站在距离2米高的人2.4米的地方,他们应该在景观的方向上填充框架。对于人像,你需要走到大约1.8米远。

That's all fine and wonderful for filling the frame. But we want to calculate for arbitrary distances, by seeing how much of the frame our subject takes up. That's what the second formula is for. Let's again use our 2m tall subject, and plug numbers in. For this experiment, let's say that we've examined our image, and the subject in the photo is taking up 1800 pixels, vertically. Plugging into the second distance formula, we get:

这对填充框架来说是很好的。但是我们想要计算任意距离,通过观察主体所占的帧数。这就是第二个公式的作用。我们再用2米高的题目,代入数字。在这个实验中,假设我们已经检查了我们的图像,照片中的主体垂直于1800像素。代入第二个距离公式,我们得到:

4.10 * 2000 * 2448
------------------  =  3260.82mm, or ~ 3.26m
    1800 * 3.42

And if the subject took up the same 1800 vertical pixels in portrait mode, then we could guess that the photographer was about 3.28m away.

如果被试在人像模式中占据了相同的1800个垂直像素,那么我们可以猜测摄影师在3.28米之外。

This all assumes that the formulae given above are correct. And again, I only did rudimentary attempts at verifying the 'full-frame' measurements (once with a subject about 28cm tall, then with a subject about 1.7m tall). But my eyeball estimates looked reasonably close to what the formula predicted.

这一切都假定上述公式是正确的。而且,我只做了一些初步的尝试来验证“全框架”的测量(曾经有一个大约28厘米高的物体,然后是一个大约1.7米高的物体)。但我的眼球估计值看起来相当接近公式的预测。