Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef IMAGE_UTIL_IMAGE_WARP_UTIL_H_
00031 #define IMAGE_UTIL_IMAGE_WARP_UTIL_H_
00032
00033 #include <vector>
00034
00035
00036 #include <boost/circular_buffer.hpp>
00037
00038
00039 #include <ros/ros.h>
00040
00041
00042 #include <opencv2/core/core.hpp>
00043 #include <opencv2/highgui/highgui.hpp>
00044 #include <opencv2/features2d/features2d.hpp>
00045 #include <opencv2/calib3d/calib3d.hpp>
00046 #include <opencv2/stitching/detail/warpers.hpp>
00047
00048
00049 #include <swri_image_util/image_matching.h>
00050
00051 namespace swri_image_util
00052 {
00053 cv::Mat WarpImage(const cv::Mat& image, double roll, double pitch);
00054
00064 void WarpPoints(
00065 double pitch,
00066 double roll,
00067 const cv::Size& image_size,
00068 const cv::Mat& pts_in,
00069 cv::Mat& pts_out);
00070
00080 void WarpPoints(
00081 double pitch,
00082 double roll,
00083 const cv::Size& image_size,
00084 const std::vector<cv::KeyPoint>& pts_in,
00085 std::vector<cv::KeyPoint>& pts_out);
00086
00097 cv::Mat GetR(double pitch, double roll, double yaw = 0.0);
00098
00099
00105 class PitchAndRollEstimator
00106 {
00107 public:
00111 PitchAndRollEstimator() {}
00112
00113
00120 cv::Mat EstimateNominalAngle(double& nominal_pitch,
00121 double& nominal_roll,
00122 bool show_image_diff = false);
00123
00124
00131 static cv::Mat EstimateNominalAngle(const cv::Mat& points1,
00132 const cv::Mat& points2,
00133 const cv::Size& image_size,
00134 double& nominal_pitch,
00135 double& nominal_roll);
00136
00137 private:
00138 cv::Mat im1_;
00139 cv::Mat im2_;
00140
00141 cv::Mat K_;
00142 cv::Mat T_;
00143
00144 std::vector<cv::KeyPoint> kp1_;
00145 std::vector<cv::KeyPoint> kp2_;
00146 cv::Mat descriptors1_;
00147 cv::Mat descriptors2_;
00148
00149 cv::Mat kp1_matched_;
00150 cv::Mat kp2_matched_;
00151
00152 cv::detail::PlaneWarper warper_;
00153
00160 bool ComputeGeometricMatches();
00161
00162
00176 static bool EstimateTransforms(cv::Mat& pts1,
00177 cv::Mat& pts2,
00178 cv::Mat& T_affine,
00179 cv::Mat& T_rigid,
00180 double& rms_error);
00181
00190 void WarpPoints(double pitch,
00191 double roll,
00192 const cv::Mat& pts_in,
00193 cv::Mat& pts_out);
00194
00202 void WarpAffinePoints(const cv::Mat& T,
00203 const cv::Mat& pts_in,
00204 cv::Mat& pts_out);
00205 };
00206
00212 class PitchAndRollEstimatorQueue
00213 {
00214 public:
00218 PitchAndRollEstimatorQueue();
00219
00220 ~PitchAndRollEstimatorQueue() {}
00221
00227 void SetBufferSize(int32_t buff_size = 50);
00228
00232 void Clear();
00233
00243 void WarpPoints(const cv::Mat& points_in,
00244 cv::Mat& points_out,
00245 const cv::Size& image_size,
00246 bool use_median = true);
00247
00256 void GenerateNewEstimate(const cv::Mat& points1,
00257 const cv::Mat& points2,
00258 const cv::Size& image_size);
00259
00266 void LoadNewData(double new_pitch,
00267 double new_roll);
00268
00279 bool GetMeanPitchAndRoll(double& pitch,
00280 double& roll);
00281
00282
00293 bool GetMedianPitchAndRoll(double& pitch,
00294 double& roll);
00295
00296 private:
00297 boost::circular_buffer<double> pitches_;
00298 boost::circular_buffer<double> rolls_;
00299
00300 double mean_pitch_;
00301 double mean_roll_;
00302 double median_pitch_;
00303 double median_roll_;
00304
00308 void ComputeStats();
00309 };
00310 }
00311
00312 #endif // IMAGE_UTIL_IMAGE_WARP_UTIL_H_