How to measure object size in real world in terms of measurement like inches centimeters etc from object size in the image in pixels?
Asked Answered
H

1

5

I have calculated object size in terms of pixel from the image containing object. I want to measure object size in real world. Is there any way to find out multiplying factor to measure actual size ? I'm currently using python for implementation.

Heterophony answered 4/2, 2017 at 2:5 Comment(4)
Possible duplicate of Calculating pixel length of an imageBerton
Yes. It should be possible to do that using mathematics.Piggery
Thank you for your quick response I have image of size 1200*800 I have detected an object of size 199 width and 150 height can you give me idea about other parameters to calculate object size let's say in centimeterHeterophony
and i have distance from the camera to object as wellHeterophony
M
7

Typically you will have obtained your image with a camera which projects the 3 dimensional scene onto a 2 dimensional sensor by means of a lens. The vertical (height) projection is represented in the following diagram ( I am assuming a rectilinear lens):

Lens Scene to Sensor projection (Vertical axis)

You say the height of your object of interest in pixels of your image as 150 pixels:

h_{obj} = 150 pixels

You say the image size has a total height of 800 pixels, assuming this is the sensor resolution:

h_{sensor} = 800 pixels

You are interested in finding the real height in metric system of the object H_{obj} that finds itself at distance D from the camera.

Expressing the angles in radians we can establish the following relationships:

D \cdot \theta = H_{obj} , f \cdot \theta = h_{obj}

where f is the focal length of the lens.

isolating terms and substituting we reach \frac{D}{f}\cdot h_{obj} = H_{obj}

but you have expressed h_{obj} in pixels and you want H_{obj} expressed in the metric system. So, lets first move from pixels to millimeters.

h_{obj} (mm) = \frac{h_{obj}(pixels)}{h_{sensor}(pixels)}\cdot h_{sensor} (mm)

Lets assume you don't know the sensor height, so we keep it as the variable for the moment. Rearranging, expressing focal length as millimeters (mm) and substituting into the previous equation we have:

D \cdot \frac{h_{obj}(pixels)}{h_{sensor}(pixels)} \cdot \frac{h_{sensor}(mm)}{f(mm)} = H_{obj}

notice the term : \frac{h_{sensor}(mm)}{f(mm)} = \alpha (radians)

\alpha represents the Vertical Field of View (since we use the sensor height) of the camera, this is a parameter that is typically given for camera & lens calculations.

3dimensional Field of View

Normally its given in degrees, so we just convert it to radians.

\frac{V_{fov}º}{180º}\cdot \pi = V_{fov} (radians)

  • If you actually know the focal length of your lens and the size of your sensor, just calculate the Field of View directly. This leaves us with the following equation:

H_{obj} = D \cdot \frac{h_{obj}(pixels)}{h_{sensor}(pixels)} \cdot V_{FOV} (radians)

The Field of View is the parameter you are missing to be able to complete your calculation. To complete the example let's assume it is 90º:

V_{FOV} = \frac{\pi}{2} (radians)

The system of units you use now to express your distance D will define the units with which the h_{obj} will be expressed in.

H_{obj} (meters) = D(meters) \cdot \frac{150}{800} \cdot \frac{\pi}{2}


Another approach is, given a Field of View, and assuming a rectilinear lens, you can calculate pixel height and pixel width at a defined distance from the camera.

Vertical resolution at distance D

V_{resolution@D(meters)} \left(\frac{mm}{pixel}\right) = \frac{1000(mm)}{1(meter)} \cdot D (meters) \cdot \frac{V_{FOV}(radians)}{V_{sensor}(pixels)}


For more information on Field of view:

Mythopoeia answered 20/2, 2017 at 22:21 Comment(5)
This is just what I've needed. I've been stopped in my project because of this problem. Cheers !!Heterophony
I've some confusion about Vfov can you explain?Heterophony
Vfov is Vertical Field of view, Hfov would be Horizontal field of View, and Field of View on its own, typically refers to the Diagonal Field of view but not always.. I have updated my answer with some links, have a read.Mythopoeia
I have calculated front width and depth of Human Neck now how can I calculate circumference of the neck. Should I consider it as elliptical or circular ?Heterophony
Hi @Sagar , this is a different question and therefore should be posted as a new question. That being said. I'm no expert about human dimensions but I would recommend you search for "Anthropometry human neck" . Anthropometry is the scientific study of the measurements and proportions of the human body. Best of luck!Mythopoeia

© 2022 - 2024 — McMap. All rights reserved.