# How to calculate distance of an object from camera or size of an object in an image? Have to utilise already generated camera parameters to find these [duplicate]

How to calculate distance of an object from camera or calculate the size of a object in an image? Given that, I have already generated the camera parameters (intrinsic and extrinsic). I have to utilise these parameters to calculate any of the above values.

• Can you clarify what you meant by the recently edited title of this question? It doesn't make the question any clearer, or help to separate it from the linked duplicates. – scottbb Apr 19 '17 at 18:37
• I have generated camera internal and external parameters using a swarm algorithm. I have to use those parameters i.e, Focal length, Rotation Matrix, Translation matrix, etc. in finding any of the assets like distance from the camera or size of object. As, I have read till now, camera parameters are very much useful in finding these values. So, I'm trying this approach. – Kartikeya Jaiswal Apr 19 '17 at 19:10

Once you focus on the subject, it should show the distance on the markings on the outside of the lens. For an ex, see http://www.kenrockwell.com/leica/images/40mm-f2/D3S_6584-1200.jpg Sorry, but can't help with the calculating the size of object on the image. I do know that macros are rated at the ratio of object on sensor/film. E.g., 1 to 1 is actual size.

The camera lens projects an image of the outside world onto the surface of film or digital imaging chip. The relationship between the actual size and the image size is a ratio. Also, the relationship between object distance and the focal length is a ratio.

We can draw imaginary lines from the boundaries of the object to center of the lens. These lines trace a triangle. Correspondingly, we can trace out a triangle from the boundaries of the image of the image object back to the center of the lens. Again a triangle shape is traced. The two triangles are “similar”, they have the same shape. All the corresponding angles are “congruent” and all the corresponding sides are “proportional”. Thus we can use a simple proportion to solve for image size and/or object distance.

As an example: An object 10 feet long is placed 50 feet from the camera. A 100mm focal length was used to take the picture of this object. How long is the image of this object? The ratio of the object’s length to the camera to subject distance is 10 ÷ 50 = 0.20. This object's image length will be 100mm X 0.20 = 20 mm long.

Using the same ration idea: A 100mm lens is used to image an object 10 feet long. The image of this object at the focal plane is 20mm long. The ratio of focal length to image length is 100 ÷ 20 = 5. How far away was the object? Answer 10 feet X 5 = 50 feet.

You can't. You can calculate one from the other (the ratio of image size on sensor to lens focal length is the same as actual subject size to distance), but if both distance and actual size are unknown you are stuck.

That is why scale models work in the special effects industry.