Search code examples
iosmathios-camera

Calculate real width based on picture, knowing distance


I know the distance between the camera and the object

I know the type of camera used

I know the width in pixel on the picture

Can I figure the real life width of the object?


Solution

    1. you have to get the angle of camera. For example, iphone 5s is 61.4 in vertical and 48.0 horizontal. call it alpha.

    2. then you calculate the width of object by this way:

      viewWidth = distance * tan(alpha / 2) * 2;

      objWidth = viewWidth * (imageWidth / screenWidth)