If you know the width of the object, and the transformation the camera applies, you could calculate it.
Observe the quick and dirty drawing below:

The weird thing on the left is the camera, the other thing on the right is the object you want to measure the width (or height, ...) of.
The camera applies a simple transformation on the scene: it shrinks (by estimation). There can be other transformations as well (wide-angle lenses and such), but I'll leave those out of the picture.
Now, to know how much the camera shrinks, you need a reference object. That's saying: you need an object in the picture, of which you know both the width and the distance to the camera. Let's name those w1
and d1
. You can measure the width on the picture, that's w1'
.
Now one more assumption: The objects should be close to each other. The objects transform more to the sides of the image, and we want them to transform in the same way.
Now, another quick and dirty drawing, zoomed in:
(E
is inside the camera, DC
is the picture, AB
is an object in the scene)
Here, we can see a Thales' Theorem forming. According to Thales, w1/w1' = EB/EC
, therefore w1/w1' = (d1+EC)/EC
. We calculate EC
(which is why we need the reference object): EC = d1 / (w1/w1' - 1)
The same can be done for the measured object (same naming conventions, but with number 2): w2/w2' = EB/EC
. Therefore, w2 = w2' * (d2 + EC) / EC
.
Now, if the two objects are close to each other on the picture, you can use the EC
we calculated with the reference object for the measured object. It's an approximation, though. It is only exact when there's an common edge.