Re: using a pixel shader for undistorting an image?



"Giff" <Giffnews@xxxxxxxxx> wrote in news:1176367731.805784.70970
@l77g2000hsb.googlegroups.com:

Hi all,

I hope some of you could give me a hint on how to proceed.
I would like to use a pixel shader to undistort the images coming from
the webcam, i.e., remove the radial distortion, so that I can free
some CPU time for other computer vision processing.

Since the camera internal parameters are constant, I thought I could
create a lookup table (in the c++ code) and then pass it to the
shader, so that for each pixel, the new destination can be easily
found in the shader.

Do you think this would work?
What is the best way to pass an array to the shader?
When I compute the lookup table, I get sub-pixel precision with the
destination for each pixel being a pair of float (x,y) within [0,h]
[0,w], where h and w are the image height and width in pixel
coordinates. Should I round this to int before passing it to the
shader? Or, instead, leave it float and maybe normalize so that the
coordinates are in [0,1]?

I am on windows and the shader would be written in hlsl.

Thanks for any suggestions.





The problem you are describing is generally known as "camera calibration" and it is related to
geometric corrections of 2-D images against lens effects, as well as calculating accurate
stereoscopic models using two or more images from different POV.

The camera calibration model is usually solved by specific systems of simultaneous equations that
are based on observations upon well-defined points in the plane. In other words, you usually take a
grid of squares and crosspoints (i.e. known geometry) and you see how each of these points is
distorted (translated in X-Y) when lens effects take place.

Provided you can provide an accurate 1-to-1 association "manually" for each of these control points
throughout the grid, 2-3 such images are usually more than enough to create a very accurate
"inverse" model for correcting any geometric distortion (with some loss in spatial resolution of course).

Due to the extent of this subject, it is not easy to post any equations here - a simple search in
Wikipedia and Google will probably direct you to detailed explanations and source code samples
(certainly Matlab, maybe C/C++ too).



--
Harris
.



Relevant Pages