Just use ratios.
If you know the length of one object, how many pixels is that in the photo? Use the ruler tool to find out.
When you divide one by the other, you'll get: # of pixels/length of object. In other words, you'll know how many pixels in the photo will represent 1 cm/metre/inch/foot, etc.