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

CameraPinholeDistor::normImageToPixelCoordinates is not implemented #2

Closed
GoogleCodeExporter opened this issue Mar 25, 2015 · 4 comments

Comments

@GoogleCodeExporter
Copy link

As this inverse transformation is not trivial, I prefer to wait Vincent's 
advises to start the implementation.

Original issue reported on code.google.com by thibault...@gmail.com on 31 May 2011 at 4:15

@GoogleCodeExporter
Copy link
Author

Hey Thibault

I might be able to help here - I spent a while working with distortion models 
during the "calibration phase" of my thesis.

"CameraPinhole::normImageToPixelCoordinates()" will convert from undistorted 
normalized coordinates to undistorted pixel co-ordinates, right?

And you want "CameraPinholeDistor::normImageToPixelCoordinates()" to convert 
from the undistorted, normalized coordinates to the DISTORTED pixel 
co-ordinates? So you are missing the step that applies a distortion model to a 
set of normalized image co-ordinates?

In that case, I have some code that might help. Obviously it will depend on the 
particular distortion model, but I implemented a solution for the rational 
model in OpenCV and it was quite simple, and I'm sure it can be adjusted to 
suit more models (such as ones using 5 or less coefficients).

Do you want me to try and implement it? Here is a bit of a sample of my old 
code:

------------------------------------------------------------

fx0 = cameraMatrix.at<double>(0, 0);
fy0 = cameraMatrix.at<double>(1, 1);
ifx0 = 1./fx0;
ify0 = 1./fy0;
cx0 = cameraMatrix.at<double>(0, 2);
cy0 = cameraMatrix.at<double>(1, 2);
// and k is an array containing the distortion model coefficients for a 
rational model

// x & y are the normalized, undistorted co-ordinates
// Determine radial and tangential distances/factors
r2 = x*x + y*y;
icdist = (1 + ((k[7]*r2 + k[6])*r2 + k[5])*r2)/(1 + ((k[4]*r2 + k[1])*r2 + 
k[0])*r2);
deltaX = 2*k[2]*x*y + k[3]*(r2 + 2*x*x);
deltaY = k[2]*(r2 + 2*y*y) + 2*k[3]*x*y;

// x_new and y_new are the re-distorted co-ordinates, but are still normalized
x_new = (x0/icdist) + deltaX;
y_new = (y0/icdist) + deltaY;

// x2 and y2 are now denormalized as well as redistorted, so should be 
equivalent to the positions on the original image
x2 = (x1/ifx0) + cx0;
y2 = (y1/ify0) + cy0;

------------------------------------------------------------

I'm happy to help with this front-end stuff (image I/O, calibration, features) 
when I can because I'm probably more knowledgable with this than I am with the 
actual SFM algorithms! 

Original comment by stephen....@gmail.com on 3 Aug 2011 at 7:43

  • Added labels: ****
  • Removed labels: ****

@GoogleCodeExporter
Copy link
Author

this would be very useful!!!
You can make changes and test via the testcamera.cpp tutorial (named "Learn 
what you can do with a pinhole distorded camera") if the 
distortion/undistortion work well. If it's the case, you can commit ;)

Original comment by thibault...@gmail.com on 12 Aug 2011 at 11:54

  • Added labels: ****
  • Removed labels: ****

@GoogleCodeExporter
Copy link
Author

Hey Thibault

OK, I've added in some re-distortion and the changes seem to work (although 
there are slight floating-point inaccuracies in the results of Test 8 Option 
1). I've committed it too (clumsily - I left out the log message accidentally 
:P). So once you've verified that the changes work feel free to close this 
issue.

Steve

Original comment by stephen....@gmail.com on 17 Aug 2011 at 2:55

  • Added labels: ****
  • Removed labels: ****

@GoogleCodeExporter
Copy link
Author

Great work! This issue is now closed!

Original comment by thibault...@gmail.com on 18 Aug 2011 at 10:48

  • Changed state: Done
  • Added labels: ****
  • Removed labels: ****

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

No branches or pull requests

1 participant