Continue to Site

# Distance calculation b/w camera and object using matlab

Status
Not open for further replies.

#### annna

##### Member level 2
Hi,
Can anybody help me. I want to measure the distance between an object and the camera through which the snap has been taken. I've came to know that using the actual area of the object I can calculate the distance using some technique. All I want to know is that technique. And if one can tell me any other solution then it will be great.........................

#### aka07

##### Member level 1
Matlab has a similar demo in the image processing toolbox. Check it out. But I am not sure if you can measure actual distance on standard scale like meter, but you can measure in pixels. But using some projections and mathematical calculation you maybe able to calculate the actual distance.

Points: 2

### esatyendra

Points: 2

#### annna

##### Member level 2
I am able to calculate the distance b/w two points in an image in pixels. But i want to calculate the one b/w object and camera. All I need are those mathematical calculations which you are talking about Can you please explain a little bit about them

esatyendra

### esatyendra

Points: 2

#### aka07

##### Member level 1
For that you need a scale which specifies that 1 pixel = " how many " meters , ( like 1 pixel= .001meters) something like that. If you have that , it should just basic calculations from which you can find the distance.

#### annna

##### Member level 2
I could not understand what you are trying to say. If I know that ratio which you mentioned above (I know DPI 'Dots Per Inch' of the image), I can know the distance from one point to another (i.e: I have to make any reference for distance measurement), But in the case of camera there is no reference for me. I will be very thankful to you if you can let me understand the technique which is going on in your mind. Hope I have not asked any silly question......

#### andre_luis

##### Super Moderator
Staff member
It is possible take geometric informatios about objects using camera.
But you need a lot of pictures, and also compute some camera parameters ( like, focal distance ).
This can be achieved by only one camera getting picures on diffrent known positions, or also several static cameras.
This method is called 3D Reconstruction.

Once all that geometry are configurated, the input images will generate a modeled spatial object in witch is possible measure the distance you want.

Take a look here :

+++

Last edited:

#### annna

##### Member level 2
What if I know the approximate distance between the camera and object and have to calculate the actual distance can i do this using one image.

#### aka07

##### Member level 1
Hi,

You did'nt ask any silly question. The basic problem is that you need some sort of prior to start with. And what Andre has mentioned in his reply is the same thing. You need multiple parameters come up with some prior to work it out. So like in his reply you need to get the scale of the focus and things like that. The basic used in 3D reconstruction is the Triangulation method , which is also used to calculate the distance of the moon from the earth , and things like that. But you cannot start with a single image and go to find the actual distances unless you have a prior knowledge or some given parameters.
I have worked on satellite images and there we are given the scale of image pixels and things would be more easy.

#### annna

##### Member level 2
okay I got it I'll be back with all that stuff soon....................

#### eyeanand

##### Junior Member level 1
ok, hi

i think what you need is perspective transformation. Since your subject is in 3D and your image is 2D the mapping done by the camera is not one to one..buts its many to one (more specifically 3 to 2) the image as such does not provide with the Z coordinate or depth information( that is what you want to find out-the distance of object from the camera).

The perspective Transformation is the method that most image processing and now a days."3D" TV sets use to introduce the depth information in the display.
it provides the basics of perspective transformation.

you need to either know a reference distance from which you can extract any other distance information or you need to know all the variables eg: focal length etc.
then you have the formulae , substitute and get the result.

Points: 2

Points: 2

Points: 2