@@ -55,7 +55,72 @@ namespace cv
55
55
// ! @{
56
56
57
57
/* * @brief Affine transform
58
- @todo document
58
+ *
59
+ * It represents a 4x4 homogeneous transformation matrix \f$T\f$
60
+ *
61
+ * \f[T =
62
+ * \begin{bmatrix}
63
+ * R & t\\
64
+ * 0 & 1\\
65
+ * \end{bmatrix}
66
+ * \f]
67
+ *
68
+ * where \f$R\f$ is a 3x3 rotation matrix and \f$t\f$ is a 3x1 translation vector.
69
+ *
70
+ * You can specify \f$R\f$ either by a 3x3 rotation matrix or by a 3x1 rotation vector,
71
+ * which is converted to a 3x3 rotation matrix by the Rodrigues formula.
72
+ *
73
+ * To construct a matrix \f$T\f$ representing first rotation around the axis \f$r\f$ with rotation
74
+ * angle \f$|r|\f$ in radian (right hand rule) and then translation by the vector \f$t\f$, you can use
75
+ *
76
+ * @code
77
+ * cv::Vec3f r, t;
78
+ * cv::Affine3f T(r, t);
79
+ * @endcode
80
+ *
81
+ * If you already have the rotation matrix \f$R\f$, then you can use
82
+ *
83
+ * @code
84
+ * cv::Matx33f R;
85
+ * cv::Affine3f T(R, t);
86
+ * @endcode
87
+ *
88
+ * To extract the rotation matrix \f$R\f$ from \f$T\f$, use
89
+ *
90
+ * @code
91
+ * cv::Matx33f R = T.rotation();
92
+ * @endcode
93
+ *
94
+ * To extract the translation vector \f$t\f$ from \f$T\f$, use
95
+ *
96
+ * @code
97
+ * cv::Vec3f t = T.translation();
98
+ * @endcode
99
+ *
100
+ * To extract the rotation vector \f$r\f$ from \f$T\f$, use
101
+ *
102
+ * @code
103
+ * cv::Vec3f r = T.rvec();
104
+ * @endcode
105
+ *
106
+ * Note that since the mapping from rotation vectors to rotation matrices
107
+ * is many to one. The returned rotation vector is not necessarily the one
108
+ * you used before to set the matrix.
109
+ *
110
+ * If you have two transformations \f$T = T_1 * T_2\f$, use
111
+ *
112
+ * @code
113
+ * cv::Affine3f T, T1, T2;
114
+ * T = T2.concatenate(T1);
115
+ * @endcode
116
+ *
117
+ * To get the inverse transform of \f$T\f$, use
118
+ *
119
+ * @code
120
+ * cv::Affine3f T, T_inv;
121
+ * T_inv = T.inv();
122
+ * @endcode
123
+ *
59
124
*/
60
125
template <typename T>
61
126
class Affine3
@@ -66,45 +131,127 @@ namespace cv
66
131
typedef Matx<float_type, 4 , 4 > Mat4;
67
132
typedef Vec<float_type, 3 > Vec3;
68
133
134
+ // ! Default constructor. It represents a 4x4 identity matrix.
69
135
Affine3 ();
70
136
71
137
// ! Augmented affine matrix
72
138
Affine3 (const Mat4& affine);
73
139
74
- // ! Rotation matrix
140
+ /* *
141
+ * The resulting 4x4 matrix is
142
+ *
143
+ * \f[
144
+ * \begin{bmatrix}
145
+ * R & t\\
146
+ * 0 & 1\\
147
+ * \end{bmatrix}
148
+ * \f]
149
+ *
150
+ * @param R 3x3 rotation matrix.
151
+ * @param t 3x1 translation vector.
152
+ */
75
153
Affine3 (const Mat3& R, const Vec3& t = Vec3::all(0 ));
76
154
77
- // ! Rodrigues vector
155
+ /* *
156
+ * Rodrigues vector.
157
+ *
158
+ * The last row of the current matrix is set to [0,0,0,1].
159
+ *
160
+ * @param rvec 3x1 rotation vector. Its direction indicates the rotation axis and its length
161
+ * indicates the rotation angle in radian (using right hand rule).
162
+ * @param t 3x1 translation vector.
163
+ */
78
164
Affine3 (const Vec3& rvec, const Vec3& t = Vec3::all(0 ));
79
165
80
- // ! Combines all contructors above. Supports 4x4, 4x3, 3x3, 1x3, 3x1 sizes of data matrix
166
+ /* *
167
+ * Combines all constructors above. Supports 4x4, 3x4, 3x3, 1x3, 3x1 sizes of data matrix.
168
+ *
169
+ * The last row of the current matrix is set to [0,0,0,1] when data is not 4x4.
170
+ *
171
+ * @param data 1-channel matrix.
172
+ * when it is 4x4, it is copied to the current matrix and t is not used.
173
+ * When it is 3x4, it is copied to the upper part 3x4 of the current matrix and t is not used.
174
+ * When it is 3x3, it is copied to the upper left 3x3 part of the current matrix.
175
+ * When it is 3x1 or 1x3, it is treated as a rotation vector and the Rodrigues formula is used
176
+ * to compute a 3x3 rotation matrix.
177
+ * @param t 3x1 translation vector. It is used only when data is neither 4x4 nor 3x4.
178
+ */
81
179
explicit Affine3 (const Mat& data, const Vec3& t = Vec3::all(0 ));
82
180
83
- // ! From 16th element array
181
+ // ! From 16- element array
84
182
explicit Affine3 (const float_type* vals);
85
183
86
- // ! Create identity transform
184
+ // ! Create an 4x4 identity transform
87
185
static Affine3 Identity ();
88
186
89
- // ! Rotation matrix
187
+ /* *
188
+ * Rotation matrix.
189
+ *
190
+ * Copy the rotation matrix to the upper left 3x3 part of the current matrix.
191
+ * The remaining elements of the current matrix are not changed.
192
+ *
193
+ * @param R 3x3 rotation matrix.
194
+ *
195
+ */
90
196
void rotation (const Mat3& R);
91
197
92
- // ! Rodrigues vector
198
+ /* *
199
+ * Rodrigues vector.
200
+ *
201
+ * It sets the upper left 3x3 part of the matrix. The remaining part is unaffected.
202
+ *
203
+ * @param rvec 3x1 rotation vector. The direction indicates the rotation axis and
204
+ * its length indicates the rotation angle in radian (using the right thumb convention).
205
+ */
93
206
void rotation (const Vec3& rvec);
94
207
95
- // ! Combines rotation methods above. Suports 3x3, 1x3, 3x1 sizes of data matrix;
208
+ /* *
209
+ * Combines rotation methods above. Supports 3x3, 1x3, 3x1 sizes of data matrix.
210
+ *
211
+ * It sets the upper left 3x3 part of the matrix. The remaining part is unaffected.
212
+ *
213
+ * @param data 1-channel matrix.
214
+ * When it is a 3x3 matrix, it sets the upper left 3x3 part of the current matrix.
215
+ * When it is a 1x3 or 3x1 matrix, it is used as a rotation vector. The Rodrigues formula
216
+ * is used to compute the rotation matrix and sets the upper left 3x3 part of the current matrix.
217
+ */
96
218
void rotation (const Mat& data);
97
219
220
+ /* *
221
+ * Copy the 3x3 matrix L to the upper left part of the current matrix
222
+ *
223
+ * It sets the upper left 3x3 part of the matrix. The remaining part is unaffected.
224
+ *
225
+ * @param L 3x3 matrix.
226
+ */
98
227
void linear (const Mat3& L);
228
+
229
+ /* *
230
+ * Copy t to the first three elements of the last column of the current matrix
231
+ *
232
+ * It sets the upper right 3x1 part of the matrix. The remaining part is unaffected.
233
+ *
234
+ * @param t 3x1 translation vector.
235
+ */
99
236
void translation (const Vec3& t);
100
237
238
+ // ! @return the upper left 3x3 part
101
239
Mat3 rotation () const ;
240
+
241
+ // ! @return the upper left 3x3 part
102
242
Mat3 linear () const ;
243
+
244
+ // ! @return the upper right 3x1 part
103
245
Vec3 translation () const ;
104
246
105
- // ! Rodrigues vector
247
+ // ! Rodrigues vector.
248
+ // ! @return a vector representing the upper left 3x3 rotation matrix of the current matrix.
249
+ // ! @warning Since the mapping between rotation vectors and rotation matrices is many to one,
250
+ // ! this function returns only one rotation vector that represents the current rotation matrix,
251
+ // ! which is not necessarily the same one set by `rotation(const Vec3& rvec)`.
106
252
Vec3 rvec () const ;
107
253
254
+ // ! @return the inverse of the current matrix.
108
255
Affine3 inv (int method = cv::DECOMP_SVD) const ;
109
256
110
257
// ! a.rotate(R) is equivalent to Affine(R, 0) * a;
@@ -113,7 +260,7 @@ namespace cv
113
260
// ! a.rotate(rvec) is equivalent to Affine(rvec, 0) * a;
114
261
Affine3 rotate (const Vec3& rvec) const ;
115
262
116
- // ! a.translate(t) is equivalent to Affine(E, t) * a;
263
+ // ! a.translate(t) is equivalent to Affine(E, t) * a, where E is an identity matrix
117
264
Affine3 translate (const Vec3& t) const ;
118
265
119
266
// ! a.concatenate(affine) is equivalent to affine * a;
@@ -136,6 +283,7 @@ namespace cv
136
283
template <typename T> static
137
284
Affine3<T> operator *(const Affine3<T>& affine1, const Affine3<T>& affine2);
138
285
286
+ // ! V is a 3-element vector with member fields x, y and z
139
287
template <typename T, typename V> static
140
288
V operator *(const Affine3<T>& affine, const V& vector);
141
289
@@ -178,7 +326,7 @@ namespace cv
178
326
// ! @cond IGNORED
179
327
180
328
// /////////////////////////////////////////////////////////////////////////////////
181
- // Implementaiton
329
+ // Implementation
182
330
183
331
template <typename T> inline
184
332
cv::Affine3<T>::Affine3()
@@ -212,6 +360,7 @@ template<typename T> inline
212
360
cv::Affine3<T>::Affine3(const cv::Mat& data, const Vec3& t)
213
361
{
214
362
CV_Assert (data.type () == cv::traits::Type<T>::value);
363
+ CV_Assert (data.channels () == 1 );
215
364
216
365
if (data.cols == 4 && data.rows == 4 )
217
366
{
@@ -276,11 +425,12 @@ void cv::Affine3<T>::rotation(const Vec3& _rvec)
276
425
}
277
426
}
278
427
279
- // Combines rotation methods above. Suports 3x3, 1x3, 3x1 sizes of data matrix;
428
+ // Combines rotation methods above. Supports 3x3, 1x3, 3x1 sizes of data matrix;
280
429
template <typename T> inline
281
430
void cv::Affine3<T>::rotation(const cv::Mat& data)
282
431
{
283
432
CV_Assert (data.type () == cv::traits::Type<T>::value);
433
+ CV_Assert (data.channels () == 1 );
284
434
285
435
if (data.cols == 3 && data.rows == 3 )
286
436
{
@@ -295,7 +445,7 @@ void cv::Affine3<T>::rotation(const cv::Mat& data)
295
445
rotation (_rvec);
296
446
}
297
447
else
298
- CV_Assert (!" Input marix can be 3x3, 1x3 or 3x1" );
448
+ CV_Assert (!" Input matrix can only be 3x3, 1x3 or 3x1" );
299
449
}
300
450
301
451
template <typename T> inline
0 commit comments