image_warp_util.h
Go to the documentation of this file.
1 // *****************************************************************************
2 //
3 // Copyright (c) 2014, Southwest Research Institute® (SwRI®)
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of Southwest Research Institute® (SwRI®) nor the
14 // names of its contributors may be used to endorse or promote products
15 // derived from this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
21 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //
28 // *****************************************************************************
29 
30 #ifndef IMAGE_UTIL_IMAGE_WARP_UTIL_H_
31 #define IMAGE_UTIL_IMAGE_WARP_UTIL_H_
32 
33 #include <vector>
34 
35 // Boost Libraries
36 #include <boost/circular_buffer.hpp>
37 
38 // ROS Libraries
39 #include <ros/ros.h>
40 
41 // OpenCV Libraries
42 #include <opencv2/core/core.hpp>
43 #include <opencv2/highgui/highgui.hpp>
44 #include <opencv2/features2d/features2d.hpp>
45 #include <opencv2/calib3d/calib3d.hpp>
46 #include <opencv2/stitching/detail/warpers.hpp>
47 
48 // RANGER Libraries
50 
51 namespace swri_image_util
52 {
53  cv::Mat WarpImage(const cv::Mat& image, double roll, double pitch);
54 
64  void WarpPoints(
65  double pitch,
66  double roll,
67  const cv::Size& image_size,
68  const cv::Mat& pts_in,
69  cv::Mat& pts_out);
70 
80  void WarpPoints(
81  double pitch,
82  double roll,
83  const cv::Size& image_size,
84  const std::vector<cv::KeyPoint>& pts_in,
85  std::vector<cv::KeyPoint>& pts_out);
86 
97  cv::Mat GetR(double pitch, double roll, double yaw = 0.0);
98 
99 
106  {
107  public:
112 
113 
120  cv::Mat EstimateNominalAngle(double& nominal_pitch,
121  double& nominal_roll,
122  bool show_image_diff = false);
123 
124 
131  static cv::Mat EstimateNominalAngle(const cv::Mat& points1,
132  const cv::Mat& points2,
133  const cv::Size& image_size,
134  double& nominal_pitch,
135  double& nominal_roll);
136 
137  private:
138  cv::Mat im1_;
139  cv::Mat im2_;
140 
141  cv::Mat K_;
142  cv::Mat T_;
143 
144  std::vector<cv::KeyPoint> kp1_;
145  std::vector<cv::KeyPoint> kp2_;
146  cv::Mat descriptors1_;
147  cv::Mat descriptors2_;
148 
149  cv::Mat kp1_matched_;
150  cv::Mat kp2_matched_;
151 
152  cv::detail::PlaneWarper warper_;
153 
161 
162 
176  static bool EstimateTransforms(cv::Mat& pts1,
177  cv::Mat& pts2,
178  cv::Mat& T_affine,
179  cv::Mat& T_rigid,
180  double& rms_error);
181 
190  void WarpPoints(double pitch,
191  double roll,
192  const cv::Mat& pts_in,
193  cv::Mat& pts_out);
194 
202  void WarpAffinePoints(const cv::Mat& T,
203  const cv::Mat& pts_in,
204  cv::Mat& pts_out);
205  };
206 
213  {
214  public:
219 
221 
227  void SetBufferSize(int32_t buff_size = 50);
228 
232  void Clear();
233 
243  void WarpPoints(const cv::Mat& points_in,
244  cv::Mat& points_out,
245  const cv::Size& image_size,
246  bool use_median = true);
247 
256  void GenerateNewEstimate(const cv::Mat& points1,
257  const cv::Mat& points2,
258  const cv::Size& image_size);
259 
266  void LoadNewData(double new_pitch,
267  double new_roll);
268 
279  bool GetMeanPitchAndRoll(double& pitch,
280  double& roll);
281 
282 
293  bool GetMedianPitchAndRoll(double& pitch,
294  double& roll);
295 
296  private:
297  boost::circular_buffer<double> pitches_;
298  boost::circular_buffer<double> rolls_;
299 
300  double mean_pitch_;
301  double mean_roll_;
303  double median_roll_;
304 
308  void ComputeStats();
309  };
310 }
311 
312 #endif // IMAGE_UTIL_IMAGE_WARP_UTIL_H_
std::vector< cv::KeyPoint > kp2_
boost::circular_buffer< double > pitches_
static bool EstimateTransforms(cv::Mat &pts1, cv::Mat &pts2, cv::Mat &T_affine, cv::Mat &T_rigid, double &rms_error)
Estimates the "nearest" rigid, and corresponding full affine transformation for a set of matching poi...
bool ComputeGeometricMatches()
Matches keypoints using loose geometric constraints and stores them in kp1_matched_ and kp2_matched_...
void WarpPoints(double pitch, double roll, const cv::Mat &pts_in, cv::Mat &pts_out)
Warps a matrix of points (in the same form as the inliers)
A class for estimating image warping based on perspective distortion. Primarily intended for use with...
void WarpAffinePoints(const cv::Mat &T, const cv::Mat &pts_in, cv::Mat &pts_out)
Warps a matrix of points (in the same form as the inliers)
boost::circular_buffer< double > rolls_
void WarpPoints(double pitch, double roll, const cv::Size &image_size, const cv::Mat &pts_in, cv::Mat &pts_out)
cv::Mat WarpImage(const cv::Mat &image, double roll, double pitch)
cv::Mat GetR(double pitch, double roll, double yaw=0.0)
Gets the rotation matrix associated with the specified pitch and roll values.
std::vector< cv::KeyPoint > kp1_
cv::Mat EstimateNominalAngle(double &nominal_pitch, double &nominal_roll, bool show_image_diff=false)
Estimates the nominal pitch and roll of the camera (from perfectly vertical) from two overlapping ima...
A class for estimating image warping based on perspective distortion. Primarily intended for use with...


swri_image_util
Author(s): Kris Kozak
autogenerated on Fri Jun 7 2019 22:05:56