ios 如何使用图像 Exif 元数据从 iPhone 相机获取物体的距离?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22634518/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to get Distance of Object from iPhone camera using image Exif meta data?
提问by 9to5ios
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 或 iphone5s。是否可以?
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
这个应用程序如何工作???欢迎所有帮助
回答by StuReeks
@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.
a) +1 给 Martin R,如果您假设地球是平坦的,则用户可以出于校准目的更新手机高度(根据您引用的应用程序),可以恢复俯仰信息并知道地面上的某个点在基地的位置你的对象是那么这是简单的触发。一旦估计了距离并假设您要测量的物体接近垂直(或以已知角度放置),则也可以计算其高度。
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 文件包含人脸区域信息。如果您对人感兴趣并且乐于假设他们是成年人,那么您可以使用您已经概述的方法使用平均头部尺寸假设来估计距离。
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 信息。
回答by colorado777
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(如果指向前方则为 0;如果向下 -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.htmlshows 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 度?即使您确实尝试使用相机焦点,它也会自动更新,我对使用变量查找相机焦点一无所知。https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/04_MediaCapture.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;
回答by Rajesh Loganathan
Its not possible way to get distance while varying ground-mobile distancedynamically from each person. Manually user have to set the height of the mobile each time to calculate.
在动态地改变每个人的地面移动距离的同时获得距离是不可能的。每次计算时,用户必须手动设置手机的高度。
回答by Dougal Campbell
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
- focal length: 4.10mm
- sensor size: 4.54 x 3.42 mm
- 像素分辨率:3264 x 2448
- 焦距:4.10mm
- 传感器尺寸:4.54 x 3.42 毫米
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:
所以:上面关于“工作距离”的第一个公式可以告诉我们给定大小的对象填充传感器框架的距离。使用横向相机和 2m 高 (2000mm) 的对象,我们得到:
(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.
因此,如果您站在距离 2m 高的人约 2.4m 的位置,他们应该以横向方式填充框架。对于肖像,您需要加紧到大约 1.8m 的距离。
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:
对于填充框架来说,这一切都很好。但是我们想要计算任意距离,通过查看我们的主题占据了多少帧。这就是第二个公式的用途。让我们再次使用我们 2m 高的主体,并插入数字。对于这个实验,假设我们已经检查了我们的图像,并且照片中的主体在垂直方向上占据了 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.28m。
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 米高的对象)。但是我的眼球估计看起来与公式预测的相当接近。