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

Image undistortion for fisheye lenses #2308

Merged
merged 5 commits into from
Aug 2, 2018
Merged

Conversation

guidoAI
Copy link
Contributor

@guidoAI guidoAI commented Aug 1, 2018

I have added undistortion functions to the vision library. These can be used to convert image coordinates from distorted fisheye lenses to undistorted coordinates and back, taking into account the camera calibration matrix and the distortion of the specific lens. The distortion function is the one from Dhane, P., Kutty, K., & Bangadkar, S. (2012). A generic non-linear method for fisheye correction. International Journal of Computer Applications, 51(10). (invertible fisheye model), as it is an invertible model.

I also made a module, undistort_image, that uses the functions to undistort a whole image. This is quite a slow process, so it is not really advisable to use this in a vision pipeline leading to control. However, it can be used to find the right undistortion parameter k, and shows that the undistortion functions work.

I have tested the functions and module on a Bebop 2, using the front image. I added a specific airframe to the TU Delft airframes for this purpose.

struct video_listener *listener = NULL;

// Camera calibration matrix (of the Bebop2 for a specific part of the visual sensor):
static float K[9] = {189.69f, 0.0f, 165.04f,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be made configurable as it is camera/drone specific

0.0f, 188.60f, 118.44f,
0.0f, 0.0f, 1.0f};

//static float k;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove unnecessary comment

//static float k;

// Function
struct image_t *undistort_image_func(struct image_t *img);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

declaration vs definition - probably no need to declare the function, unless you want to put this in a separate header

struct image_t img_distorted;
image_create(&img_distorted, img->w, img->h, img->type);
// this info is not created in image_create, but is necessary for streaming...:
//img_distorted.ts = img->ts;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so should it be here?

for(float x_n = min_x_normalized; x_n < max_x_normalized; x_n += normalized_step, x++) {
uint32_t y = 0;
for(float y_n = min_y_normalized; y_n < max_y_normalized; y_n += normalized_step, y++) {
// for faster execution but smaller FOV, uncomment the next line:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be controllable via a flag or a variable that the user can switch on/off

@guidoAI
Copy link
Contributor Author

guidoAI commented Aug 1, 2018

As described in the newest commit, cdf55d6, I followed up on all advice, adding camera calibration parameters and removing unnecessary comments.

@OpenUAS OpenUAS added this to the v5.14 milestone Aug 2, 2018
@OpenUAS OpenUAS merged commit f1da313 into paparazzi:master Aug 2, 2018
@OpenUAS
Copy link
Contributor

OpenUAS commented Aug 2, 2018

Was talking about the "Documentation" of the XML module, it had this incorrect line. No worries, I honord the pull and will fixup the documentation self. BTW I also have only "limited time™" . 😉

@guidoAI
Copy link
Contributor Author

guidoAI commented Aug 2, 2018

Thanks for looking at it and merging it.

On my mobile phone, the description tags did not show, so I only saw that "the colorfilter" was incorrect...

You can use this as a description:
Undistortion module. It takes a fisheye image and undistorts it with the help of a camera calibration matrix and distortion parameters, as given by the user.

biancabndris pushed a commit to biancabndris/paparazzi that referenced this pull request Aug 29, 2018
* Addition of an undistortion module that has the supporting functions for undistorting fisheye camera images
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants