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..
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.
"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.
...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.
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.
Asked: 2015-03-04 06:30:21 -0600
Seen: 6,514 times
Last updated: Mar 04 '15
OpenCV DescriptorMatcher matches
Conversion between IplImage and MxArray
Video On Label OpenCV Qt :: hide cvNamedWindows
Problems using the math.h class with OpenCV (c++, VS2012)
How to reduce false positives for face detection
Area of a single pixel object in OpenCV
build problems for android_binary_package - Eclipse Indigo, Ubuntu 12.04
Can't compile .cu file when including opencv.hpp
Using OpenCV's stitching module, strange error when compositing images