File: motion_estimation.rst

package info (click to toggle)
opencv 2.4.9.1%2Bdfsg-1%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 126,800 kB
  • ctags: 62,729
  • sloc: xml: 509,055; cpp: 490,794; lisp: 23,208; python: 21,174; java: 19,317; ansic: 1,038; sh: 128; makefile: 72
file content (240 lines) | stat: -rw-r--r-- 8,085 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
Rotation Estimation
===================

.. highlight:: cpp

detail::Estimator
-----------------
.. ocv:class:: detail::Estimator

Rotation estimator base class. It takes features of all images, pairwise matches between all images and estimates rotations of all cameras.

.. note:: The coordinate system origin is implementation-dependent, but you can always normalize the rotations in respect to the first camera, for instance.

::

    class CV_EXPORTS Estimator
    {
    public:
        virtual ~Estimator() {}

        void operator ()(const std::vector<ImageFeatures> &features, const std::vector<MatchesInfo> &pairwise_matches,
                         std::vector<CameraParams> &cameras)
            { estimate(features, pairwise_matches, cameras); }

    protected:
        virtual void estimate(const std::vector<ImageFeatures> &features, const std::vector<MatchesInfo> &pairwise_matches,
                              std::vector<CameraParams> &cameras) = 0;
    };

detail::Estimator::operator()
-----------------------------

Estimates camera parameters.

.. ocv:function:: detail::Estimator::operator ()(const std::vector<ImageFeatures> &features, const std::vector<MatchesInfo> &pairwise_matches, std::vector<CameraParams> &cameras)

    :param features: Features of images

    :param pairwise_matches: Pairwise matches of images

    :param cameras: Estimated camera parameters

detail::Estimator::estimate
---------------------------

This method must implement camera parameters estimation logic in order to make the wrapper `detail::Estimator::operator()`_ work.

.. ocv:function:: void detail::Estimator::estimate(const std::vector<ImageFeatures> &features, const std::vector<MatchesInfo> &pairwise_matches, std::vector<CameraParams> &cameras)

    :param features: Features of images

    :param pairwise_matches: Pairwise matches of images

    :param cameras: Estimated camera parameters

detail::HomographyBasedEstimator
--------------------------------
.. ocv:class:: detail::HomographyBasedEstimator : public detail::Estimator

Homography based rotation estimator. ::

    class CV_EXPORTS HomographyBasedEstimator : public Estimator
    {
    public:
        HomographyBasedEstimator(bool is_focals_estimated = false)
            : is_focals_estimated_(is_focals_estimated) {}

    private:
        /* hidden */
    };

detail::BundleAdjusterBase
--------------------------
.. ocv:class:: detail::BundleAdjusterBase : public detail::Estimator

Base class for all camera parameters refinement methods. ::

    class CV_EXPORTS BundleAdjusterBase : public Estimator
    {
    public:
        const Mat refinementMask() const { return refinement_mask_.clone(); }
        void setRefinementMask(const Mat &mask)
        {
            CV_Assert(mask.type() == CV_8U && mask.size() == Size(3, 3));
            refinement_mask_ = mask.clone();
        }

        double confThresh() const { return conf_thresh_; }
        void setConfThresh(double conf_thresh) { conf_thresh_ = conf_thresh; }

        CvTermCriteria termCriteria() { return term_criteria_; }
        void setTermCriteria(const CvTermCriteria& term_criteria) { term_criteria_ = term_criteria; }

    protected:
        BundleAdjusterBase(int num_params_per_cam, int num_errs_per_measurement)
            : num_params_per_cam_(num_params_per_cam),
              num_errs_per_measurement_(num_errs_per_measurement)
        {
            setRefinementMask(Mat::ones(3, 3, CV_8U));
            setConfThresh(1.);
            setTermCriteria(cvTermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 1000, DBL_EPSILON));
        }

        // Runs bundle adjustment
        virtual void estimate(const std::vector<ImageFeatures> &features,
                              const std::vector<MatchesInfo> &pairwise_matches,
                              std::vector<CameraParams> &cameras);

        virtual void setUpInitialCameraParams(const std::vector<CameraParams> &cameras) = 0;
        virtual void obtainRefinedCameraParams(std::vector<CameraParams> &cameras) const = 0;
        virtual void calcError(Mat &err) = 0;
        virtual void calcJacobian(Mat &jac) = 0;

        // 3x3 8U mask, where 0 means don't refine respective parameter, != 0 means refine
        Mat refinement_mask_;

        int num_images_;
        int total_num_matches_;

        int num_params_per_cam_;
        int num_errs_per_measurement_;

        const ImageFeatures *features_;
        const MatchesInfo *pairwise_matches_;

        // Threshold to filter out poorly matched image pairs
        double conf_thresh_;

        //Levenberg–Marquardt algorithm termination criteria
        CvTermCriteria term_criteria_;

        // Camera parameters matrix (CV_64F)
        Mat cam_params_;

        // Connected images pairs
        std::vector<std::pair<int,int> > edges_;
    };

.. seealso:: :ocv:class:`detail::Estimator`

detail::BundleAdjusterBase::BundleAdjusterBase
----------------------------------------------

Construct a bundle adjuster base instance.

.. ocv:function:: detail::BundleAdjusterBase::BundleAdjusterBase(int num_params_per_cam, int num_errs_per_measurement)

    :param num_params_per_cam: Number of parameters per camera

    :param num_errs_per_measurement: Number of error terms (components) per match

detail::BundleAdjusterBase::setUpInitialCameraParams
----------------------------------------------------

Sets initial camera parameter to refine.

.. ocv:function:: void detail::BundleAdjusterBase::setUpInitialCameraParams(const std::vector<CameraParams> &cameras)

    :param cameras: Camera parameters

detail::BundleAdjusterBase::calcError
-------------------------------------

Calculates error vector.

.. ocv:function:: void detail::BundleAdjusterBase::calcError(Mat &err)

    :param err: Error column-vector of length ``total_num_matches * num_errs_per_measurement``

detail::BundleAdjusterBase::calcJacobian
----------------------------------------

Calculates the cost function jacobian.

.. ocv:function:: void detail::BundleAdjusterBase::calcJacobian(Mat &jac)

    :param jac: Jacobian matrix of dimensions ``(total_num_matches * num_errs_per_measurement) x (num_images * num_params_per_cam)``

detail::BundleAdjusterBase::obtainRefinedCameraParams
-----------------------------------------------------

Gets the refined camera parameters.

.. ocv:function:: void detail::BundleAdjusterBase::obtainRefinedCameraParams(std::vector<CameraParams> &cameras) const

    :param cameras: Refined camera parameters

detail::BundleAdjusterReproj
----------------------------
.. ocv:class:: detail::BundleAdjusterReproj : public detail::BundleAdjusterBase

Implementation of the camera parameters refinement algorithm which minimizes sum of the reprojection error squares. ::

    class CV_EXPORTS BundleAdjusterReproj : public BundleAdjusterBase
    {
    public:
        BundleAdjusterReproj() : BundleAdjusterBase(7, 2) {}

    private:
        /* hidden */
    };

.. seealso:: :ocv:class:`detail::BundleAdjusterBase`, :ocv:class:`detail::Estimator`

detail::BundleAdjusterRay
-------------------------
.. ocv:class:: detail::BundleAdjusterRay : public detail::BundleAdjusterBase

Implementation of the camera parameters refinement algorithm which minimizes sum of the distances between the rays passing through the camera center and a feature. ::

    class CV_EXPORTS BundleAdjusterRay : public BundleAdjusterBase
    {
    public:
        BundleAdjusterRay() : BundleAdjusterBase(4, 3) {}

    private:
        /* hidden */
    };

.. seealso:: :ocv:class:`detail::BundleAdjusterBase`

detail::WaveCorrectKind
-----------------------
Wave correction kind.

.. ocv:enum:: detail::WaveCorrectKind

  .. ocv:emember:: WAVE_CORRECT_HORIZ
  .. ocv:emember:: WAVE_CORRECT_VERT


detail::waveCorrect
-------------------
Tries to make panorama more horizontal (or vertical).

.. ocv:function:: void detail::waveCorrect(std::vector<Mat> &rmats, WaveCorrectKind kind)

    :param rmats: Camera rotation matrices.

    :param kind: Correction kind, see :ocv:enum:`detail::WaveCorrectKind`.