Matthias Preu
Matthias Preu

Reputation: 803

Distort a straight line via fisheye distortion function and draw it correctly in image

I have a line in world coordinates and project it to an image (as described in this question math.stackexchange). This results in a simple line equation in image space, so I can easily print it with OpenCV inside an image.

Now I want to project the line into a fisheye camera image. Since I have a corresponding non-linear distortion function I'm able to distort points easily. The naive way is now to distort each point from the generated line via this function. But that would lead to several line segments and unset pixels (which would normally belong to the distorted line).

I wonder what could be a clever way to get a correct distorted line. Maybe it is also necessary to handle the line projection in a different way? I could sample the straigt line more often (i.e. using subpixel coordinates), but I think that don't guarantee me a correct solution.

EDIT:

My distortion function is a simple polynom

r(a) = k1*a+k2*a^2+k3*a^3+k4*a^4

where a is the angle of the undistorted incident ray to the optical axis and r is the radius to a pixel in the distorted image. Your can read more about that here.

Upvotes: 1

Views: 953

Answers (1)

Elad Joseph
Elad Joseph

Reputation: 3068

The simple solution is indeed to increase your line resolution. If you add more pixels (sub-pixels are better), then you will get a better looking image after the distortion.

I think the more correct way is backward-mapping. Find the mapping from each pixel (square,integer) in the distorted image into the pixel (quadrilateral, real) in the undistorted image. This will make sure you won't have any holes in your distorted line.

enter image description here

Upvotes: 1

Related Questions