I would like to calculate the real world distance between two objects, given that I know how far away each one is from the camera, and the distance between them in the picture (in pixels).
Is there a way to find their actual distance given this information?
I tried to draw a triangle and solve it mathematically, but it seems not feasible cause there is not much information. Anything that I might be missing?
Edit: I solved it by using the focal length of the camera, the field of view degrees and the total pixels of the image width. I used trigonometry to calculate the angle and then the cosine rule for the distance.
How a pixel on-screen relates to the angle of a real-world object is going to be heavily influenced by the field of view and other properties of the camera/lens.
(Picture how a fisheye lens impacts where objects appear, for an extreme example)
If you can get to the point where you can calculate the real-world angle between two objects based on where their pixels appear on the image, you should have enough information to solve via trigonometry.
That means your solution will be device- and lens- specific.