correct fisheye distortion

Posted by Will on Stack Overflow See other posts from Stack Overflow or by Will
Published on 2010-03-19T13:50:13Z Indexed on 2010/03/19 13:51 UTC
Read the original article Hit count: 457

Filed under:
|
|

I have some points that describe positions in a picture taken with a fisheye lens.

I've found this description of how to generate a fisheye effect, but not how to reverse it.

How do you calculate the radial distance from the centre to go from fisheye to rectilinear?

My function stub looks like this:

Point correct_fisheye(const Point& p,const Size& img) {
    // to polar
    const Point centre = {img.width/2,img.height/2};
    const Point rel = {p.x-centre.x,p.y-centre.y};
    const double theta = atan2(rel.y,rel.x);
    double R = sqrt((rel.x*rel.x)+(rel.y*rel.y));
    // fisheye undistortion in here please
    //... change R ...
    // back to rectangular
    const Point ret = Point(centre.x+R*cos(theta),centre.y+R*sin(theta));
    fprintf(stderr,"(%d,%d) in (%d,%d) = %f,%f = (%d,%d)\n",p.x,p.y,img.width,img.height,theta,R,ret.x,ret.y);
    return ret;
}

© Stack Overflow or respective owner

Related posts about graphics

Related posts about math