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
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #ifndef __OPENCV_STITCHING_MOTION_ESTIMATORS_HPP__
00044 #define __OPENCV_STITCHING_MOTION_ESTIMATORS_HPP__
00045
00046 #include "opencv2/core/core.hpp"
00047 #include "matchers.hpp"
00048 #include "util.hpp"
00049 #include "camera.hpp"
00050
00051 namespace cv {
00052 namespace detail {
00053
00054 class CV_EXPORTS Estimator
00055 {
00056 public:
00057 virtual ~Estimator() {}
00058
00059 void operator ()(const std::vector<ImageFeatures> &features, const std::vector<MatchesInfo> &pairwise_matches,
00060 std::vector<CameraParams> &cameras)
00061 { estimate(features, pairwise_matches, cameras); }
00062
00063 protected:
00064 virtual void estimate(const std::vector<ImageFeatures> &features, const std::vector<MatchesInfo> &pairwise_matches,
00065 std::vector<CameraParams> &cameras) = 0;
00066 };
00067
00068
00069 class CV_EXPORTS HomographyBasedEstimator : public Estimator
00070 {
00071 public:
00072 HomographyBasedEstimator(bool is_focals_estimated = false)
00073 : is_focals_estimated_(is_focals_estimated) {}
00074
00075 private:
00076 void estimate(const std::vector<ImageFeatures> &features, const std::vector<MatchesInfo> &pairwise_matches,
00077 std::vector<CameraParams> &cameras);
00078
00079 bool is_focals_estimated_;
00080 };
00081
00082
00083 class CV_EXPORTS BundleAdjusterBase : public Estimator
00084 {
00085 public:
00086 const Mat refinementMask() const { return refinement_mask_.clone(); }
00087 void setRefinementMask(const Mat &mask)
00088 {
00089 CV_Assert(mask.type() == CV_8U && mask.size() == Size(3, 3));
00090 refinement_mask_ = mask.clone();
00091 }
00092
00093 double confThresh() const { return conf_thresh_; }
00094 void setConfThresh(double conf_thresh) { conf_thresh_ = conf_thresh; }
00095
00096 CvTermCriteria termCriteria() { return term_criteria_; }
00097 void setTermCriteria(const CvTermCriteria& term_criteria) { term_criteria_ = term_criteria; }
00098
00099 protected:
00100 BundleAdjusterBase(int num_params_per_cam, int num_errs_per_measurement)
00101 : num_params_per_cam_(num_params_per_cam),
00102 num_errs_per_measurement_(num_errs_per_measurement)
00103 {
00104 setRefinementMask(Mat::ones(3, 3, CV_8U));
00105 setConfThresh(1.);
00106 setTermCriteria(cvTermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 1000, DBL_EPSILON));
00107 }
00108
00109
00110 virtual void estimate(const std::vector<ImageFeatures> &features,
00111 const std::vector<MatchesInfo> &pairwise_matches,
00112 std::vector<CameraParams> &cameras);
00113
00114 virtual void setUpInitialCameraParams(const std::vector<CameraParams> &cameras) = 0;
00115 virtual void obtainRefinedCameraParams(std::vector<CameraParams> &cameras) const = 0;
00116 virtual void calcError(Mat &err) = 0;
00117 virtual void calcJacobian(Mat &jac) = 0;
00118
00119
00120 Mat refinement_mask_;
00121
00122 int num_images_;
00123 int total_num_matches_;
00124
00125 int num_params_per_cam_;
00126 int num_errs_per_measurement_;
00127
00128 const ImageFeatures *features_;
00129 const MatchesInfo *pairwise_matches_;
00130
00131
00132 double conf_thresh_;
00133
00134
00135 CvTermCriteria term_criteria_;
00136
00137
00138 Mat cam_params_;
00139
00140
00141 std::vector<std::pair<int,int> > edges_;
00142 };
00143
00144
00145
00146
00147
00148 class CV_EXPORTS BundleAdjusterReproj : public BundleAdjusterBase
00149 {
00150 public:
00151 BundleAdjusterReproj() : BundleAdjusterBase(7, 2) {}
00152
00153 private:
00154 void setUpInitialCameraParams(const std::vector<CameraParams> &cameras);
00155 void obtainRefinedCameraParams(std::vector<CameraParams> &cameras) const;
00156 void calcError(Mat &err);
00157 void calcJacobian(Mat &jac);
00158
00159 Mat err1_, err2_;
00160 };
00161
00162
00163
00164
00165 class CV_EXPORTS BundleAdjusterRay : public BundleAdjusterBase
00166 {
00167 public:
00168 BundleAdjusterRay() : BundleAdjusterBase(4, 3) {}
00169
00170 private:
00171 void setUpInitialCameraParams(const std::vector<CameraParams> &cameras);
00172 void obtainRefinedCameraParams(std::vector<CameraParams> &cameras) const;
00173 void calcError(Mat &err);
00174 void calcJacobian(Mat &jac);
00175
00176 Mat err1_, err2_;
00177 };
00178
00179
00180 enum WaveCorrectKind
00181 {
00182 WAVE_CORRECT_HORIZ,
00183 WAVE_CORRECT_VERT
00184 };
00185
00186 void CV_EXPORTS waveCorrect(std::vector<Mat> &rmats, WaveCorrectKind kind);
00187
00188
00190
00191
00192
00193 std::string CV_EXPORTS matchesGraphAsString(std::vector<std::string> &pathes, std::vector<MatchesInfo> &pairwise_matches,
00194 float conf_threshold);
00195
00196 std::vector<int> CV_EXPORTS leaveBiggestComponent(std::vector<ImageFeatures> &features, std::vector<MatchesInfo> &pairwise_matches,
00197 float conf_threshold);
00198
00199 void CV_EXPORTS findMaxSpanningTree(int num_images, const std::vector<MatchesInfo> &pairwise_matches,
00200 Graph &span_tree, std::vector<int> ¢ers);
00201
00202 }
00203 }
00204
00205 #endif // __OPENCV_STITCHING_MOTION_ESTIMATORS_HPP__