diff --git a/README.md b/README.md index 2ca0b79..46659c0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,31 @@ -VIKIT ------ +## Vikit for FAST-LIVO2 -Vikit (Vision-Kit) provides some tools for your vision/robotics project. -Far from stable. +Vikit (Vision-Kit) is a lightweight and efficient library providing essential camera models, mathematical utilities, and interpolation functions for the FAST-LIVO2 framework. + +📬 For further assistance or inquiries, please contact Chunran Zheng at zhengcr@connect.hku.hk. + +### Supported Camera Models +Vikit supports the following camera models: + +- Pinhole + Radtan +- Pinhole + Equidistant **(with OpenCV-based fisheye distortion correction)** +- Pinhole + ATAN +- Pinhole + Polynomial +- Omni + Polynomial + +These models accommodate diverse camera configurations and distortion characteristics. + +### Project Lineage +This repository is maintained as a downstream fork with the following lineage: +1. Original work: [xuankuzcr/rpg_vikit](https://github.com/xuankuzcr/rpg_vikit) by Chunran Zheng. +2. ROS2-compatible port: [integralrobotics/rpg_vikit](https://github.com/integralrobotics/rpg_vikit). + +### Enhancements +The following key improvements have been implemented: +- Integrated OpenCV-based fisheye distortion correction into the equidistant camera model (`vikit_common` module). + +### Acknowledgments +Special recognition to: +- [UZH-RPG group](https://rpg.ifi.uzh.ch/) for foundational [rpg_vikit](https://github.com/uzh-rpg/rpg_vikit) research. +- [Chunran Zheng](https://github.com/xuankuzcr/rpg_vikit) for developing the ROS1-compatible version [xuankuzcr/rpg_vikit](https://github.com/xuankuzcr/rpg_vikit) specifically adapted for FAST-LIVO2. +- [integralrobotics](https://github.com/integralrobotics) for porting Chunran Zheng's version to ROS2 in their [rpg_vikit implementation](https://github.com/integralrobotics/rpg_vikit). \ No newline at end of file diff --git a/vikit_common/include/vikit/equidistant_camera.h b/vikit_common/include/vikit/equidistant_camera.h index 72a5e43..b1f2f96 100644 --- a/vikit_common/include/vikit/equidistant_camera.h +++ b/vikit_common/include/vikit/equidistant_camera.h @@ -137,6 +137,9 @@ class EquidistantCamera : public AbstractCamera { virtual double fy() const { return fy_; }; virtual double cx() const { return cx_; }; virtual double cy() const { return cy_; }; + + // Undistort the input image to correct lens distortion + void undistortImage(const cv::Mat& input, cv::Mat& output) const; }; } // end namespace vk diff --git a/vikit_common/src/equidistant_camera.cpp b/vikit_common/src/equidistant_camera.cpp index 2fa5224..55f2653 100644 --- a/vikit_common/src/equidistant_camera.cpp +++ b/vikit_common/src/equidistant_camera.cpp @@ -108,4 +108,27 @@ world2cam(const Vector2d& uv) const return px; } +void EquidistantCamera::undistortImage(const cv::Mat& input, cv::Mat& output) const +{ + // Return original image if no distortion parameters are available + if(!distortion_) { + output = input.clone(); + return; + } + // Camera intrinsic matrix K and fisheye distortion coefficients (k1..k4). + cv::Mat K = (cv::Mat_(3, 3) << fx_, 0.0, cx_, + 0.0, fy_, cy_, + 0.0, 0.0, 1.0); + cv::Mat D = (cv::Mat_(4, 1) << k1_, k2_, k3_, k4_); + // Estimate a new camera matrix that keeps the field of view, instead of + // reusing K, which would crop the rectified image for wide fisheye lenses. + // balance in [0, 1] trades retained field of view (1.0) against black + // borders (0.0); tune it to the lens if needed. + const double balance = 0.0; + cv::Mat new_K; + cv::fisheye::estimateNewCameraMatrixForUndistortRectify( + K, D, input.size(), cv::Mat::eye(3, 3, CV_64F), new_K, balance); + cv::fisheye::undistortImage(input, output, K, D, new_K); +} + } // end namespace vk