Ask Your Question

# Converting pixel displacement into other unit?

How would anyone using OpenCV convert a displacement based on pixel convert it to mm or radians, or some other unit..

edit retag close merge delete

## 1 answer

Sort by » oldest newest most voted

The first thing is you would need is to have some sort of calibration that tells you what the pixels in the image correspond to. This factor depends on your camera, lens and object distance and needs to be measured in a realistic imaging scenario.

For example if a 1 meter object exactly fits in a 512x512 pixel frame, your calibration would be (1000/512)=1.953 mm/pixel (or 0.512 pixel/mm). You can then convert pixel based displacements to real world displacements using this factor.

more

## Comments

"You can then convert pixel based displacements to real world displacements using this factor. "

No you can't. Pixel distances correspond to angular distances. If you move to Points with fixed distance (e.g. 2 cm) from the center of your 1m2 object to the edge, their pixel distance will decrease although their real world distance is the same.

I know that horizontal view of the camera is 45 degrees, and picture dimensions is 1024x768... how can i use that solve my problem..

1

...that would mean 45/1027=0.04 degrees/pixels (that's 0.00077 radians) angular resolution (call it Alpha0).

If you know the distance D of a point from the camera, calculate the distance in pixels from the image center (Dc=sqrt((x-xc)²+(y-yc)²)). The real world distance (Dw) of the point from the optical axis of the camera is:

Dw=D*sin(Dc*Alpha0)
`

To get the angular distance simply multiply Dc with Alpha0.

Alpha0 and Dc are easy to calculate, but to have the real world position, you need to know the distance from the camera.

So.. lets say that the distance is 1 meter. would ´Dw´ give me the result in radians.. I am quite having a hard time understanding your equation above.

Let's take a concrete example: your pixel close to the left edge, on the middle; coordinates: (12, 384). The middle of the screen is (512,384). Then the pixel distance between the middle of the screen and the point is Dc=500, the angular distance is 5000.04=20 degrees. If that point's distance from the camera is D=1m, then it is at 1sin(500*0.04)=0.34m distance from the optical axis of the camera.

Official site

GitHub

Wiki

Documentation

## Stats

Asked: 2015-03-04 06:30:21 -0500

Seen: 5,415 times

Last updated: Mar 04 '15