Ask Your Question

Converting pixel displacement into other unit?

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

215 gravatar image

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

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

answered 2015-03-04 13:36:49 -0500

Guyygarty gravatar image

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.

edit flag offensive delete link more


"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 1m`2 object to the edge, their pixel distance will decrease although their real world distance is the same.

FooBar gravatar imageFooBar ( 2015-03-05 04:13:42 -0500 )edit

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

215 gravatar image215 ( 2015-03-05 05:54:58 -0500 )edit

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


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.

kbarni gravatar imagekbarni ( 2015-03-06 09:38:37 -0500 )edit

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.

215 gravatar image215 ( 2015-03-09 11:19:37 -0500 )edit

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.

kbarni gravatar imagekbarni ( 2015-03-09 12:29:30 -0500 )edit

Dsin(DcAlpha0) what unit is this operating in?

215 gravatar image215 ( 2015-06-09 07:33:45 -0500 )edit

Question Tools

1 follower


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

Seen: 5,415 times

Last updated: Mar 04 '15