Determine new coordinates of pixel after calibration + remap

asked 2020-09-25 05:21:10 -0600

Shassk gravatar image

I'm trying to calibrate camera and I need to be able to determine where to moves each pixel of the original image.

As far as I understand initUndistortRectifyMap creates horizontal and vertical maps (map1 and map2) for remap as a result of some mathematical functions but I honestly did not quite get all the math behind it.

I think I get the idea of how x'' and y'' are calculated (also can you check if I get it right on this screenshot from Maple?) but I can't understand what's going on with s and x''' & y'''.

Calculations up to x'' and y''

Here's code. As far as I understand in my case R is identity matrix and all distortion coefficients apart from k1,k2,p1,p2,k3 are zeroes.

auto result = calibrateCamera(objectPoints, // the 3D points
    imagePoints,  // the image points
    imageSize,    // image size
    cameraMatrix, // output camera matrix
    distCoeffs,   // output distortion matrix
    rvecs, tvecs, // Rs, Ts 
    flag);        // set options
// . . .
cv::initUndistortRectifyMap(
    cameraMatrix,  // computed camera matrix
    distCoeffs,    // computed distortion matrix
    cv::Mat(),     // optional rectification (none) 
    cv::Mat(),     // camera matrix to generate undistorted
    cv::Size(640, 480), // size of undistorted
    CV_32FC1,      // type of output map
    map1, map2);   // the x and y mapping functions
edit retag flag offensive close merge delete