Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Undistort image before estimating pose using solvePnP

I have to estimate the pose of the camera using a known marker. The camera is calibrated and I have all the calibration coefficients.

The current version of the algorithm extracts 4 co-planar points from the frame and uses them to estimate the pose using the solvePnP function.

The algorithms seems to work fine but I have a doubt. Since the solvePnP takes as input also the calibration coefficients, do I need to undistort the image before looking the 4 points?

In the following code, are the initUndistortRectifyMap/remap functions necessary?

while(1) {

    frame = camera->getFrame();

    imshow("frame", frame);

    // Estimation of Map1 and Map2 for image rectification (to be done only on the first iteration)
    if (initRectifyMap_flag)
        // Rectify the image
        // The initialization of the Rectification Parameters will be carried out only at the first frame.
        initUndistortRectifyMap(cameraMatrix, distCoeffs, Mat(), getOptimalNewCameraMatrix(cameraMatrix, distCoeffs, frame.size(), 1, frame.size(), 0), frame.size(), CV_16SC2, map1, map2);
        initRectifyMap_flag = false;

    // Remapping of the current frame
    remap(frame, src, map1, map2, INTER_LINEAR, BORDER_TRANSPARENT, Scalar::all(255));

    // Here is the code for the extraction of the 4 points based on the content of the variable src

    // Pose estimation
    solvePnP(Mat(refMarkerPoint), Mat(markerPoints), cameraMatrix, distCoeffs, rvec, tvec,false);