pythonopencvimage-processingpixel# How to measure object size in real world in terms of measurement like inches centimeters etc from object size in the image in pixels?

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.

Solution

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**):

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

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

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:

where **f** is the focal length of the lens.

isolating terms and substituting we reach

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.

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:

\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.

Normally its given in degrees, so we just convert it to 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:

**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º:

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.

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

For more information on Field of view:

- How to tackle a 'str' not callable error message
- Importing pandas and cplex in a conda environment raises an ImportError: libstdc++.so.6: version `GLIBCXX_3.4.29' not found
- How to tell Flatpak-builder / meson to run python with command line options
- Enabling and Validating Bit Parity between C++ and Python
- Compare two lists elementwise with OR
- How to get process status using pid?
- How to handle missing values (NaN) in categorical data when using scikit-learn OneHotEncoder?
- Python simple socket client/server using asyncio
- How to give a Pydantic list field a default value?
- How can I insert NULL data into MySQL database with Python?
- I want to get the dictionary key based on its values
- Couldn't use data file .coverage: unable to open database file
- PyTorch throws batch size error with any value but 1
- Currency formatting in Python
- DRF: Serialize field with different serializers and many=True
- Using strptime to get UTC offset with separation between hours and minutes
- Generating a list of random numbers, summing to 1
- Python print function stopped working after installing super-gradients in Google Colab
- Is there a way to have tuples woking fine as index in Pandas?
- Check for multiple value pairs in dictionary
- Run setup function from setuptools only if __name__ == "__main__"?
- GCP : Bigquery to export data with CRLF as line termination
- How to automatically add users to a JSON file for a daily streak command in a Discord bot?
- pytorch split array by list of indices
- Django - TailwindCSS won't load some attributes
- Is Any is the same as Forall a.a?
- How to group dataframe rows into list in polars group_by
- Using Kepler GL without Jupyter Notebook
- how to create an list of a specific type but empty
- Define a list with type