<p>I may be misunderstanding what you're asking, but if you know the sensor size and the number of pixels in the object, then you can calculate the object size. For example, a <a href="http://www.dpreview.com/products/canon/slrs/canon_eos7d/specifications" rel="nofollow noreferrer">Canon 7D</a> has an APS-C sensor that's 22.3 x 14.9mm and 5184 x 3456 pixels. That works out to ~0.0043mm/pixel. So if you have an object that's 250 pixels wide, then the projection of the object onto the sensor would have been 250 pixels * 0.0043mm/pixel = 1.075mm wide.</p>

<p><strong>EDIT:</strong>
So just for fun, I gave this a try. I took a 300mm ruler, put it at 1 meter from the camera and shot it with a 50mm lens on a Canon 7D. According to the ruler tool in Photoshop, it was 3734 pixels wide. That gives me the following equation:</p>

<p>3734 * 0.0043 = (300 * 50) / 1000</p>

<p>or</p>

<p>16.0562 = 15.0</p>

<p>Well, it's close, but not exact. (Over by 7%.) My guess is that the sensor site size is actually slightly smaller than 0.0043mm or the sensor size is slightly bigger than the reported size. In fact, the specs for the camera say 18MP effective size, but 19MP actual sensor size. So I'm not sure what that means, but I'm guessing it explains the difference between my actual result and the calculated result. (Either that or I'm misreading the length in Photoshop and it should actually be 3488 pixels instead of 3734.) But it was fun to try!</p>

<p><strong>2nd EDIT:</strong> <a href="https://photo.stackexchange.com/questions/69582/why-isnt-my-computation-of-the-actual-size-of-an-object-in-a-photograph-matchin">This question on the Photo Stack Exchange</a> explains it. Camera lenses are often slightly longer or shorter than claimed, but rounded to the nearest nice focal length. So (assuming my calculations and measurements were correct) my lens is actually a ~53.5mm lens.</p>

CC BY-SA 3.0
2016-07-14T14:13:43.323Z
Does that estimate the distance of the real world object?
joojaa
CC BY-SA 3.0
2016-07-14T15:55:02.413Z
I'm not sure. I was trying to interpret the equation you put up. But I'll give it a try with a ruler when I get home tonight and post the results here.
user1118321
CC BY-SA 3.0
2016-07-14T19:15:28.217Z
This was exactly what I wanted, a conversion system. A straight forward one from the sensor size is not good enough because cameras usually crop part of the image they receive.
Thankfully though most cameras will have something called pixel size (in microns usually) which is exactly the conversion measure needed for this!
Kronephon
CC BY-SA 3.0
2016-07-24T19:44:46.350Z
Focal length is also affected by your camera focus. so in the course of shooting the focal length varies slightly because that is how the focus is achieved, by moving the elements. This is why you use lots of measurements and a ransac on the image to estimae the actual values better. So not only is your effective value different from spec, its diffenet in each camera and in each shot. Also your ruler may not be perfectly aligned to camera and the camera.lense not being a perfect pinhole etc.
joojaa
CC BY-SA 3.0
2016-07-26T16:29:52.933Z
Maybe you can perform several experiments on your ruler to calibrate the parameters of your camera. Or just use samples to estimate parameters directly by regression.
TheBusyTypist
CC BY-SA 3.0
2016-07-14T05:02:41.603Z
2016-07-15T02:50:37.330Z
2017-04-13T12:44:05.773Z
user1118321
<p>Yes, theoretically, for the sphere no for other things in image. If it is possible to augment the situation then it is possible to measure anything you can track much more reliably. First, knowing the scale of a object that you can successfully track is a requirement to getting a scale for the image as the cameras lost all scaling info. But this requirement alone is not enough.</p>

<p>In practice you do not know the other settings of a camera (unless calibrated with stereo geometry first), all kinds of problems arise when you do real camera tracking. Such as real cameras lens not being ideal. By tracking more than 2 features on the scene you can automatically estimate the actual focal distances and camera distortions. More importantly you can get an error estimate on your data.</p>

<p>One way is to have two photos from different angles in a scene with enough depth variation (for a stationary object this is quite easy). You can then use stereo geometry to solve the depth many such tracker apps exist as part special effects packages and making your own is not entirely out of the question (fun link, <a href="https://www.youtube.com/watch?v=DgGV3l82NTk" rel="nofollow">fundamental matrix song</a>). The second way is to have a known plane, the plane can be solved by knowing 4 points and their relative locations. In reality it is better use more points for error and lens correction estimates. A third way is to use structured light (a cloud of laser light points, or a line for example) to triangulate the point distances. Or you could use a light field camera.</p>

CC BY-SA 3.0
2016-07-13T17:40:43.970Z
2016-07-14T19:15:13.060Z
2016-07-14T19:15:13.060Z
joojaa
<p>I'm not really sure if this is possible but it should be.</p>

<p>I currently have a photo of a sphere, whose radius I've measures physically. Knowing the apparent size of the sphere from the photo and all internal camera parameters is it possible to estimate the distance from the camera to the sphere?</p>

<p>There is an equation, more used in lens imaging that is useful:</p>

<p>object_image_size = (real_object_size * lens_focal_length)/object distance</p>

<p>Problem is my object_image_size is in pixels and I need to convert it to a real world measure, preferable the size that actually showed up on the sensor. </p>

<mathematics><pixels><conversion>
Estimating real world object distance from photo
Kronephon
# Estimating real world object distance from photo

(Asked by: username_0 on 2016-07-13)

I'm not really sure if this is possible but it should be.

I currently have a photo of a sphere, whose radius I've measures physically. Knowing the apparent size of the sphere from the photo and all internal camera parameters is it possible to estimate the distance from the camera to the sphere?

There is an equation, more used in lens imaging that is useful:

object\_image\_size = (real\_object\_size \* lens\_focal\_length)/object distance

Problem is my object\_image\_size is in pixels and I need to convert it to a real world measure, preferable the size that actually showed up on the sensor.

**Tags:** mathematics, pixels, conversion


---

## 2 answers

### Answer by username_1 on 2016-07-14. Score: 3 | Accepted answer

I may be misunderstanding what you're asking, but if you know the sensor size and the number of pixels in the object, then you can calculate the object size. For example, a [Canon 7D](http://www.dpreview.com/products/canon/slrs/canon_eos7d/specifications) has an APS-C sensor that's 22.3 x 14.9mm and 5184 x 3456 pixels. That works out to ~0.0043mm/pixel. So if you have an object that's 250 pixels wide, then the projection of the object onto the sensor would have been 250 pixels \* 0.0043mm/pixel = 1.075mm wide.

**EDIT:**
So just for fun, I gave this a try. I took a 300mm ruler, put it at 1 meter from the camera and shot it with a 50mm lens on a Canon 7D. According to the ruler tool in Photoshop, it was 3734 pixels wide. That gives me the following equation:

3734 \* 0.0043 = (300 \* 50) / 1000

or

16.0562 = 15.0

Well, it's close, but not exact. (Over by 7%.) My guess is that the sensor site size is actually slightly smaller than 0.0043mm or the sensor size is slightly bigger than the reported size. In fact, the specs for the camera say 18MP effective size, but 19MP actual sensor size. So I'm not sure what that means, but I'm guessing it explains the difference between my actual result and the calculated result. (Either that or I'm misreading the length in Photoshop and it should actually be 3488 pixels instead of 3734.) But it was fun to try!

**2nd EDIT:** [This question on the Photo Stack Exchange](https://photo.stackexchange.com/questions/69582/why-isnt-my-computation-of-the-actual-size-of-an-object-in-a-photograph-matchin) explains it. Camera lenses are often slightly longer or shorter than claimed, but rounded to the nearest nice focal length. So (assuming my calculations and measurements were correct) my lens is actually a ~53.5mm lens.

> **Comments:**
> **username_2**: Does that estimate the distance of the real world object?  
> **username_1**: I'm not sure. I was trying to interpret the equation you put up. But I'll give it a try with a ruler when I get home tonight and post the results here.  
> **username_0**: This was exactly what I wanted, a conversion system. A straight forward one from the sensor size is not good enough because cameras usually crop part of the image they receive. Thankfully though most cameras will have something called pixel size (in microns usually) which is exactly the conversion measure needed for this!  
> **username_2**: Focal length is also affected by your camera focus. so in the course of shooting the focal length varies slightly because that is how the focus is achieved, by moving the elements. This is why you use lots of measurements and a ransac on the image to estimae the actual values better. So not only is your effective value different from spec, its diffenet in each camera and in each shot. Also your ruler may not be perfectly aligned to camera and the camera.lense not being a perfect pinhole etc.  
> **username_3**: Maybe you can perform several experiments on your ruler to calibrate the parameters of your camera. Or just use samples to estimate parameters directly by regression.  

---

### Answer by username_2 on 2016-07-13. Score: 3

Yes, theoretically, for the sphere no for other things in image. If it is possible to augment the situation then it is possible to measure anything you can track much more reliably. First, knowing the scale of a object that you can successfully track is a requirement to getting a scale for the image as the cameras lost all scaling info. But this requirement alone is not enough.

In practice you do not know the other settings of a camera (unless calibrated with stereo geometry first), all kinds of problems arise when you do real camera tracking. Such as real cameras lens not being ideal. By tracking more than 2 features on the scene you can automatically estimate the actual focal distances and camera distortions. More importantly you can get an error estimate on your data.

One way is to have two photos from different angles in a scene with enough depth variation (for a stationary object this is quite easy). You can then use stereo geometry to solve the depth many such tracker apps exist as part special effects packages and making your own is not entirely out of the question (fun link, [fundamental matrix song](https://www.youtube.com/watch?v=DgGV3l82NTk)). The second way is to have a known plane, the plane can be solved by knowing 4 points and their relative locations. In reality it is better use more points for error and lens correction estimates. A third way is to use structured light (a cloud of laser light points, or a line for example) to triangulate the point distances. Or you could use a light field camera.


---

