Undistortion a fisheyelens distortion of a whole image
Note that 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.
The code also can be used to convert image coordinates from distorted fisheye lenses to undistorted coordinates and back. It takes into account the camera calibration matrix and the distortion of the specific lens.
Example for airframe file
Add to your firmware section: This example contains all possible configuration options, not all of them are mandatory!
<module name="cv_undistort_image">
b'<define name="UNDISTORT_MIN_X_NORMALIZED" value="-2.0" />\n '
b'<define name="UNDISTORT_MAX_X_NORMALIZED" value="2.0" />\n '
b'<define name="UNDISTORT_FPS" value="0" />\n '
b'<define name="UNDISTORT_CAMERA" value="bottom_camera|front_camera" />\n '
b'<define name="UNDISTORT_CENTER_RATIO" value="1.0" />\n '
</module>
Module configuration options
Define Options
- name:
UNDISTORT_MIN_X_NORMALIZED
value: -2.0
Description: Minimal normalized x-coordinate to be used for the undistortion
- name:
UNDISTORT_MAX_X_NORMALIZED
value: 2.0
Description: Maximal normalized x-coordinate to be used for the undistortion
- name:
UNDISTORT_FPS
value: 0
Description: The (maximum) frequency to run the calculations at. If zero, it will max out at the camera frame rate
- name:
UNDISTORT_CAMERA
value: bottom_camera|front_camera
Description: The V4L2 camera device that is used for the calculations
- name:
UNDISTORT_CENTER_RATIO
value: 1.0
Description: If smaller than 1 only generate pixels for the center_ratio times the min_x to max_x interval. This makes undistortion quicker, but for a smaller FOV.
Module functions
Init Functions
These initialization functions are called once on startup.
Files
Header Files
The following headers are automatically included in modules.h
Source Files
Raw cv_undistort_image.xml file:
<!DOCTYPE module SYSTEM "module.dtd">
<module name="cv_undistort_image" dir="computer_vision">
<doc>
<description>
Undistortion a fisheyelens distortion of a whole image.
Note that 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.
The code also can be used to convert image coordinates from distorted fisheye lenses to undistorted coordinates and back.
It takes into account the camera calibration matrix and the distortion of the specific lens.
</description>
<define name="UNDISTORT_MIN_X_NORMALIZED" value="-2.0" description="Minimal normalized x-coordinate to be used for the undistortion"/>
<define name="UNDISTORT_MAX_X_NORMALIZED" value="2.0" description="Maximal normalized x-coordinate to be used for the undistortion"/>
<define name="UNDISTORT_FPS" value="0" description="The (maximum) frequency to run the calculations at. If zero, it will max out at the camera frame rate"/>
<define name="UNDISTORT_CAMERA" value="bottom_camera|front_camera" description="The V4L2 camera device that is used for the calculations"/>
<define name="UNDISTORT_CENTER_RATIO" value="1.0" description="If smaller than 1 only generate pixels for the center_ratio times the min_x to max_x interval. This makes undistortion quicker, but for a smaller FOV."/>
</doc>
<settings>
<dl_settings>
<dl_settings NAME="Undistort">
<dl_setting var="min_x_normalized" min="-4.0" step="0.1" max="0.0" shortname="min_x_n" param="UNDISTORT_MIN_X_NORMALIZED"/>
<dl_setting var="max_x_normalized" min="0.1" step="0.1" max="4.0" shortname="max_x_n" param="UNDISTORT_MAX_X_NORMALIZED"/>
<dl_setting var="camera_intrinsics.Dhane_k" min="1.0" step="0.01" max="2.5" shortname="dhane_k" param="UNDISTORT_DHANE_K"/>
<dl_setting var="center_ratio" min="0.05" step="0.01" max="1.0" shortname="center_ratio" param="UNDISTORT_CENTER_RATIO"/>
<dl_setting var="camera_intrinsics.focal_x" min="0.0" step="0.05" max="1024.0" shortname="focal_x" param="UNDISTORT_FOCAL_X"/>
<dl_setting var="camera_intrinsics.center_x" min="0.0" step="0.05" max="1024.0" shortname="center_x" param="UNDISTORT_CENTER_X"/>
<dl_setting var="camera_intrinsics.focal_y" min="0.0" step="0.05" max="1024.0" shortname="focal_y" param="UNDISTORT_FOCAL_Y"/>
<dl_setting var="camera_intrinsics.center_y" min="0.0" step="0.05" max="1024.0" shortname="center_y" param="UNDISTORT_CENTER_Y"/>
</dl_settings>
</dl_settings>
</settings>
<dep>
<depends>video_thread</depends>
</dep>
<header>
<file name="undistort_image.h"/>
</header>
<init fun="undistort_image_init()"/>
<makefile target="ap|nps">
<file name="undistort_image.c"/>
<file name="image.c" dir="modules/computer_vision/lib/vision"/>
<file name="undistortion.c" dir="modules/computer_vision/lib/vision"/>
</makefile>
</module>