How can I estimate an object's real size from one image if I know the camera-to-subject distance?
Asked 10/31/2022
3 views
2 answers
0
I need to estimate the real width/size of an object from a single image when I already know the distance from the camera to the object. The object is the only thing in frame, so I can't include a reference object of known size.
What formula relates object size, subject distance, focal length, and the size of the object in pixels? If I can't get reliable sensor or focal-length specifications for the camera, can I calibrate the system using sample images taken at known distances and known object sizes, then reuse that calibration to convert pixels to real-world size?
Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0
Photography Stack Exchange contributor
3y ago
2 Answers
3
You can calculate that distance given the formula for the pinhole camera model (which is an approximation, but should work well in the cases of interest). You need to know the focal distance (which by assumption, you should know — in practice, you can usually extract it from the EXIF data of the image) and the size of each pixel.
For the size of a pixel, you don't need to obtain it "experimentally" from sample images to determine the ratio. If you know the size of the sensor and the resolution, you're done. For example, on a 24Mpix full-frame sensor camera, the size of the sensor is 36mm by 24mm, and resolution is 6000 by 4000 (approximately — for example, my camera is actually 6064 by 4040, and I think it is 35.9mm by 23.9mm or something like that). That means that the pixel to mm conversion factor is 166.67 pixels per mm, or 0.006 mm per pixel (pixels should normally be perfectly square, meaning that the factor should be the same in both axes).
So, given a subject of size s pixels in the image when shot at a distance d from the camera, your formula for the size of the actual object, S given a focal length f would be:
S / d = s / f (this is because the triangle between the pinhole and the image plane, with sides f (distance from the pinhole to the image plane) and s is proportional to the triangle from the pinhole to the subject (sides d and S.
Applying the conversion factor to express s in mm instead of in pixels, you get:
S = d (any units) · s (px) · 0.006 (mm/px) / f (mm)
This gives you the size of the subject in the same units that you used for the distance of the subject to the camera (since the mm of the pix to mm factor cancels out with the mm of the focal distance, and the pixels just cancel out)
EDIT:
As you do not have information on the geometry of the camera (focal length or sensor/pixel size), you would be left with what you suggested: knowing that the actual size of the object is proportional to the size in the image (in pixels) and also to the distance, by a factor that depends on the focal length and pixel size, then you determine this factor experimentally: take an image of an object of a known size, at a known distance, and obtain the factor. This factor would correspond to the 0.006 / f in the equation above:
S = d (any units) · s (px) · camera_scaling_factor
Therefore:
camera_scaling_factor = S / ( d · s )
(notice that the actual size of your reference object and its distance to the camera need to be in the same units)
Originally by user95113. Source · Licensed CC BY-SA 4.0
user95113
3y ago
0
Generated from our catalog & community — verify before relying on it.
Yes. Using the pinhole-camera approximation, the projected sensor size of an object is
s = (f × S) / D
where S is the real object size, D is subject distance, and f is focal length. Pixel size is linearly related to sensor size, so if the object measures p pixels in the image, then:
p = k × s
Combining them:
S = (D × p) / (k × f)
Since k and f are constant for a fixed camera/lens/zoom setting, combine them into one calibration constant K:
S = (D × p) / K
You can find K from any calibration image where you know distance D, real size S, and measured pixel size p:
K = (D × p) / S
Then reuse that K for future images.
Important: this only works reliably if the camera setup stays fixed (same focal length/zoom, resolution, focus behavior, and minimal distortion) and the object is roughly perpendicular to the camera axis. If you know sensor size and image resolution, you can also derive pixel size directly instead of calibrating experimentally.
Recommended products
UniqueBot
AI3y ago
Your Answer
Related Questions
How can I estimate an object's size in pixels from its real size, distance, and camera settings?
How can I estimate an object's real size from photographs if one object in the image has a known size?
Can moving the camera and comparing object size in the frame be used to estimate distance?
How can I estimate an object's real size from pixel size, focal length, and subject distance?
How can I estimate real-world measurement precision from a camera's resolution?