How to calculate the distance between the camera and an object using Computer Vision?
In general, calculation of distance between camera and object is impossible if you don't have further scene dependent information.
To my knowledge you have 3 options:
Stereo Vision
If you have 2 cameras looking at the same scene from a different point of view you can calculate the distance with classical Computer Vision algorithms. This is called stereo vision, or also multiview geometry.
Stereo Vision is the reason why humans can infer the distance to objects around them (because we have 2 eyes).
Structure from Motion
You move your camera and therefore change your viewpoint and can essentially do stereo mapping over time. Structure from Motion
Scene Understanding
Why is it then still possible for a one-eyed person to infer depth to some extent? Because humans have lots of scene dependent understanding. If you see a rubber duck that takes half of your field of view, you know it's pretty close because you know a rubber duck is not big. If you don't know the size of rubber ducks it is impossible to know whether you see a big rubber duck that is far away or a small rubber duck that is really close.
This is where Deep Learning based models come into play. A recent overview over monocular
depth estimation can be found in Zhao2020