Computer Vision‎ > ‎POV-Ray‎ > ‎

Simulation of Lens Distortion

Cameras have lenses and do usually not resemble perfect pinhole cameras. Therefore, lens distortion models have been developed that allow a lens correction on the input images of a camera and warp them to undistorted cameras of the corresponding pinhole camera.
A widely used distortion model is described on the documentation page of the OpenCV library and the homepage of the Camera Calibration Toolbox for Matlab of Jean-Yves Bouguet.
To generate synthetic images containing lens distortion, one usually has to apply the distortion after the rendering process, at least with POV-Ray. To overcome this drawback, I have written a patch to POV-Ray 3.6.1 that introduces a new camera type.


To install the patch, download the source archive of POV-Ray 3.6.1 and extract it:
tar xfj povray-3.6.tar.bz2
Then download the patch into the same directory and execute:
patch -p0 < ../povray-3.6.1_LenseDistortion.patch

Now you can build and install your own version of POV-Ray:
cd povray-3.6.1
./configure COMPILED_BY="someone"
make install


To use the new camera, take a look at the following example snippet:
#local f  = 800.0;
#local sx = 1.0;
#local sy = 1.0;
#local fx = f / sx;
#local fy = -f / sy;
#local w  = 800.0;
#local h  = 600.0;
#local cx = w/2.0 - 0.5;
#local cy = h/2.0 - 0.5;

camera {
    location  <0,0,0>
    direction <0,0,1>
    up        <0,1,0>
    right     <1,0,0>
    focal_length    <fx, fy>
    principal_point <cx, cy>
    distortion_k1   -0.2908670
    distortion_k2   0.1094130
    distortion_k3   0.0
    distortion_p1   -0.0006320
    distortion_p2   -0.0007160

    rotate    <0.0, -120.0, 0.0>
    translate <50,10,30>



The pixel coordinate system is assumed to have its origin at the center of the upper left pixel!