Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undistorting the image #44

Closed
anushl9o5 opened this issue May 21, 2021 · 2 comments
Closed

Undistorting the image #44

anushl9o5 opened this issue May 21, 2021 · 2 comments

Comments

@anushl9o5
Copy link

Hey, I followed what you mentioned in #22 .

  • First I unproject with pinhole parameters.
  • Then I project with the calibrated model.

Here are my results, it looks like it gets even more distorted.

Distorted

001

Undistorted

undistorted

Pinhole unprojection code

bool Unproject_pinhole(Eigen::Vector2d pix, Eigen::Vector3d* direction, Eigen::Matrix3d K_inv)
{
    Eigen::Vector3d pix_hmg;
    pix_hmg[0] = pix[0];
    pix_hmg[1] = pix[1];
    pix_hmg[2] = 1.0;
    
    *direction = K_inv*pix_hmg;

    return true;
}

@anushl9o5 anushl9o5 changed the title Issue undistorting the image Undistorting the image May 21, 2021
@puzzlepaint
Copy link
Owner

The result indeed clearly looks wrong. The lines which are straight in reality should become straight in the undistorted image.

If the coefficients of K_inv are set correctly for your unprojection function, then I think that it should work. The mistake might be somewhere else. (Side note: I think that it might be helpful to pass objects such as Eigen::Matrix3d by reference rather than by value to ensure that they are not copied.)

So I can only guess. One possible mistake which can result in increasing the distortion rather than removing it would be to swap the roles of the coordinates. The correct algorithm is to use the pixel coordinate that is computed by unprojection and projection to look up the pixel color in the distorted image, and then write this color into the undistorted image at the original pixel coordinate (that was used for unprojection). If instead the original pixel coordinate is used to look up the color in the distorted image, and this color is written into the result image at the distorted coordinate, then the distortion may be increased.

@anushl9o5
Copy link
Author

So I can only guess. One possible mistake which can result in increasing the distortion rather than removing it would be to swap the roles of the coordinates. The correct algorithm is to use the pixel coordinate that is computed by unprojection and projection to look up the pixel color in the distorted image, and then write this color into the undistorted image at the original pixel coordinate (that was used for unprojection). If instead the original pixel coordinate is used to look up the color in the distorted image, and this color is written into the result image at the distorted coordinate, then the distortion may be increased.

Thanks a lot, for some reason I was doing the opposite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants