Fisheye distortion rectification with lookup table
<p>I have a fisheye lens:</p>

<p><a href="https://i.stack.imgur.com/Qw1v4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Qw1v4.png" alt="curved chess"></a></p>

<p>I would like to undistort it. I apply the FOV model:</p>

<pre><code>rd = 1 / ω * arctan (2 * ru * tan(ω / 2))   //Equation 13
ru = tan(rd * ω) / 2 / tan(ω / 2)           //Equation 14
</code></pre>

<p>as found in equations (13) and (14) of the INRIA paper "Straight lines have to be straight" <a href="https://hal.inria.fr/inria-00267247/document" rel="nofollow noreferrer">https://hal.inria.fr/inria-00267247/document</a>.</p>

<p>The code implementation is the following:</p>

<pre><code>Point2f distortPoint(float w, float h, float cx, float cy, float omega, Point2f input) {
    //w = width of the image
    //h = height of the image
    //cx = center of the lens in the image, aka w/2
    //cy = center of the lens in the image, aka h/2

    Point2f tmp = new Point2f();

    //We normalize the coordinates of the point
    tmp.x = input.x / w - cx / w;
    tmp.y = input.y / h - cy / h;

    //We apply the INRIA key formula (FOV model)
    double ru = sqrt(tmp.x * tmp.x + tmp.y * tmp.y);
    double rd = 1.0f / omega * atan(2.0f * ru * tan(omega / 2.0f));

    tmp.x *= rd / ru;
    tmp.y *= rd / ru;

    //We "un-normalize" the point
    Point2f ret = new Point2f();
    ret.x = (tmp.x + cx / w) * w;
    ret.y = (tmp.y + cy / h) * h;

    return ret;
}
</code></pre>

<p>I then used the OpenCV remap function:</p>

<pre><code>//map_x and map_y are computed with distortPoint
remap(img, imgUndistorted, map_x, map_y, INTER_LINEAR, BORDER_CONSTANT, Scalar(0, 0, 0));
</code></pre>

<p>I managed to get the distortion model from the lens manufacturer. It's a table of image_height as a function of the field angle:</p>

<pre><code>Field angle(deg)    Image Height (mm)
0                   0
1                   height1
2                   height2
3                   height3
...
89                  height89
90                  height90
</code></pre>

<p>To give an idea, each height is small and inferior to 2mm.</p>

<p>I found an interesting paper here: <a href="https://www.altera.com/content/dam/altera-www/global/en_US/pdfs/literature/wp/wp-01073-flexible-architecture-fisheye-correction-automotive-rear-view-cameras.pdf" rel="nofollow noreferrer">https://www.altera.com/content/dam/altera-www/global/en_US/pdfs/literature/wp/wp-01073-flexible-architecture-fisheye-correction-automotive-rear-view-cameras.pdf</a></p>

<p>How can I modify my pixel-unit undistortion function to factor in the mm-unit table provided by the manufacturer in order to have the most accurate possible undistorted image?</p>