2

I have a fisheye lens:

curved chess

I would like to undistort it. I apply the FOV model:

rd = 1 / ω * arctan (2 * ru * tan(ω / 2))   //Equation 13
ru = tan(rd * ω) / 2 / tan(ω / 2)           //Equation 14

as found in equations (13) and (14) of the INRIA paper "Straight lines have to be straight" https://hal.inria.fr/inria-00267247/document.

The code implementation is the following:

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;
}

I then used the OpenCV remap function:

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

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:

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

To give an idea, each height is small and inferior to 2mm.

I found an interesting paper here: 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

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?

gregoiregentil
  • 1,793
  • 1
  • 26
  • 56
  • This looks interesting, but on a mobile here i'm not that invested in all the reading. Is it possible that instead of linking thode papers, to try commenting your code well and use descriptive variable names? – Lamar Latrell Apr 05 '16 at 22:39
  • Well, I extracted the key formula from the INRIA paper. The code is the implementation of the formula. I'm not sure what you are expecting more. – gregoiregentil Apr 06 '16 at 00:33
  • Do you know the camera sensor's size accurately? In that case conversion pixel/mm should be pretty straightforward – alexisrozhkov Apr 06 '16 at 08:06
  • Yes, I have the pixel size on the sensor (1.4um x 1.4um) and I have also the image area. So how do I use such data to answer my question? – gregoiregentil Apr 06 '16 at 16:13
  • @gregoiregentil, In *general* I am expecting that if you commented your code and used descriptive variable names more that you might receive more interest in your query - i.e. the solution you're after :). Not garunteed, but it stands to reason ... – Lamar Latrell Apr 06 '16 at 20:30
  • I have comments on quasi each line of the code and I think that w h cx cy input ret are pretty descriptive variable names. We are spoiling the comments on this question. – gregoiregentil Apr 06 '16 at 22:20
  • I don't get it. You want to undistort the image but you call `distortPoint` with eq. 13? Shouldn't you call eq. 14? – Santiago Gil Aug 02 '17 at 08:38

0 Answers0