从JPG文件的EXIF信息估计焦距

转载 2016年10月15日 21:20:20

转载自:Estimating the focal length of a photo from EXIF tags

When you take a photo with almost any digital camera, the camera embeds useful information about the photo into the JPEG file itself. This often includes information about exposure time, focus, aperture, whether the flash was activated, and focal length. The last of these, focal length, is especially useful when creating panoramas. This page describes how to extract the focal length from the EXIF tags of a digital photo and to convert it to pixel units, so that it can be used in the panorama stitcher. 


Step One: Extracting the EXIF tags

First you'll need to extract the EXIF tags from the JPEG file (let's call it "foo.jpg"). To do so, we need an EXIF reader. There are many programs that will do this, but I recommend "jhead" because it is lightweight and simple to use. You can download jhead here:

Jhead webpage 
direct link to Windows executable

Once you have jhead, you can run "jhead foo.jpg" from the command line, which will output something like this:

Sample jhead output:

File name    : foo.jpg
File size    : 463023 bytes
File date    : 2001:08:12 21:02:04
Camera make  : Canon
Camera model : Canon PowerShot S100
Date/Time    : 2001:08:05 15:39:33
Resolution   : 1600 x 1200
Flash used   : No
Focal length :  5.4mm  (35mm equivalent: 36mm)
CCD Width    : 5.23mm
Exposure time: 0.100 s  (1/10)
Aperture     : f/2.8
Focus Dist.  : 1.18m
Metering Mode: center weight
Jpeg process : Baseline
The field you're looking for is focal length. In this case, the focal length is listed as "5.4mm". We'll need to convert this to pixels to use this in the panorama stitcher.

Step Two: Finding the CCD width

Once we have the focal length in millimeters, a simple formula can be used to convert to focal length in pixels. First, however, we'll need to know the width of the image sensor of your camera. Sometimes this is listed in the EXIF tags (see the "CCD Width" field in the example above). In my experience, this number can be wrong, so it's better to verify it online. A good place to find it is dpreview; if our camera was the one that took the image above, the Canon PowerShot S100, we would Google "dpreview Canon PowerShot S100 specifications." The second link that comes up is "Canon PowerShot S100 digital camera specifications"; this is the one we want. On the resulting page, search for "sensor size". For the S100, the sensor size is given as 1/2.7"" (5.27 x 3.96 mm). This is a little different from the CCD width given in the EXIF tags, but probably not enough to make a difference. I would use the width on dpreview (5.27mm), as it is usually more reliable.

Sometimes the CCD width on dpreview is given as a ratio of inches (e.g., 1/2.7""). The conversion from these units to millimeters is not straightforward, but you can look up the mapping here.

If you have trouble finding the sensor size, please contact the TAs. 


Step Three: Converting from millimeters to pixels

Once we know the focal length (in mm) and the CCD width (in mm), we can easily convert to focal length in pixels. The one last piece of information we need is the width of the image in pixels. This is given by jhead in the "Resolution" field; in the example above, the width in pixels is 1600. Now, to convert to focal length in pixels, we use the formula:

focal length in pixels = (image width in pixels) * (focal length in mm) / (CCD width in mm)

For the example photo above taken with the Canon PowerShot S100, this would be:

focal length in pixels = 1600 pixels * 5.4mm / 5.27mm   = 1639.47 pixels

So the focal length we would use for the stitcher is 1639.47.


c语言实现将exif信息加到jpg

  • 2009年12月23日 18:15
  • 7KB
  • 下载

读取jpg文件的exif信息

照片有点多,准备整理一下,按照片拍照的时间进行重新整理,用python写了一个,只读自己感兴趣的exif信息的脚本,看看速度怎么样。 以前用.net写过一个,用的现成的exif类库:大约开启1...
  • realduke2000
  • realduke2000
  • 2014年03月14日 12:52
  • 2807

数码照片的JPG文件高级信息(用C#读取图片的EXIF信息)

数码相机的照片很多,而且文件名也不直观,所以写了个程序批量改名,就是把文件名都改成相机的拍照日期,呵呵,谁知道拍照日期不是那么好取,在csdn里开了一帖,谢谢网友帮忙,终于搞定!把代码放在下面了,说不...
  • abiho
  • abiho
  • 2005年09月27日 15:36
  • 3512

读取JPG图片的Exif属性(三) - Exif属性读取GPS信息代码(C/C++实现)

Exif中GPS格式 本文是最后一篇关于Exif文章,终于要挑战最大的boss了,这个GPS信息的读取,我找了国内外很多资料都没有找 真正的实例。所以自己前两篇的基础上推断而来的。 读取JPG图片...
  • fioletfly
  • fioletfly
  • 2017年01月06日 09:12
  • 4222

读取JPG图片的Exif属性(一) - Exif信息简介

Exif 是什么? Exif就是用来记录拍摄图像时的各种信息:图像信息(厂商,分辨率等),相机拍摄记录(ISO,白平衡,饱和度,锐度等),缩略图(缩略图宽度,高度等),gps(拍摄时的经度,纬度,高...
  • fioletfly
  • fioletfly
  • 2016年12月13日 08:47
  • 6424

读取JPG图片的Exif属性(二) - C代码实现

读区Exif属性简介         读取Exif基本上就是在懂得Exif的格式的基础上,详细见上文:Exif 学习心得 - Exif 基础学习,然后就是对图片的数据进行字节分析了。这个分析也是非常...
  • fioletfly
  • fioletfly
  • 2017年01月05日 16:42
  • 2389

利用照片携带的EXIF来估计焦距等信息

(本文章大部分内容参考Noah Snavely) 等你利用数码相机拍摄照片时,相机常常会在图片中嵌入很多有用的信息到JPEG文件中。通常涵盖曝光时间、焦点、(照相机,望远镜等的)光圈、是否闪...
  • u010922186
  • u010922186
  • 2014年12月19日 14:18
  • 1610

jpg图片的Exif及gps信息和示例分析

转自:http://www.verydemo.com/demo_c173_i10439.html jpg图片的Exif及gps信息和示例分析 分类: 操作系...
  • yapingmcu
  • yapingmcu
  • 2016年02月05日 17:24
  • 7846

图片文件Exif信息详细说明

转过来,资料找了蛮久 原博客网址 当前,几乎新型的数码相机都使用Exif文件格式来存储图像. 它的规格是由 JEIDA 来制定的, 但是在互联网上还没有开放的文档可供浏览.因此我根据从互联网上所...
  • libins
  • libins
  • 2016年03月24日 17:34
  • 2452

读取和修改JPEG图片文件的头信息EXIF和JFIF

1. JPEG图片格式的历程和简单介绍可参考下面这篇文章 http://blog.csdn.net/kickxxx/article/details/8173332 ...
  • xywy2008
  • xywy2008
  • 2014年07月24日 22:43
  • 9186
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:从JPG文件的EXIF信息估计焦距
举报原因:
原因补充:

(最多只允许输入30个字)