44
#ifndef OPENCV_CORE_AFFINE3_HPP
45
#define OPENCV_CORE_AFFINE3_HPP
49
#include <opencv2/core.hpp>
129
typedef
T float_type;
130
typedef
Matx<float_type, 3, 3> Mat3;
131
typedef
Matx<float_type, 4, 4> Mat4;
132
typedef
Vec<float_type, 3> Vec3;
138
Affine3(
const
Mat4& affine);
153
Affine3(
const
Mat3& R,
const
Vec3& t = Vec3::all(0));
164
Affine3(
const
Vec3& rvec,
const
Vec3& t = Vec3::all(0));
179
explicit
Affine3(
const
Mat& data,
const
Vec3& t = Vec3::all(0));
182
explicit
Affine3(
const
float_type* vals);
185
static
Affine3 Identity();
196
void
rotation(
const
Mat3& R);
206
void
rotation(
const
Vec3& rvec);
218
void
rotation(
const
Mat& data);
227
void
linear(
const
Mat3& L);
236
void
translation(
const
Vec3& t);
239
Mat3 rotation()
const;
245
Vec3 translation()
const;
258
Affine3
rotate(
const
Mat3& R)
const;
261
Affine3
rotate(
const
Vec3& rvec)
const;
264
Affine3 translate(
const
Vec3& t)
const;
267
Affine3 concatenate(
const
Affine3& affine)
const;
269
template
<
typename
Y>
operator
Affine3<Y>()
const;
271
template
<
typename
Y> Affine3<Y> cast()
const;
275
#if defined EIGEN_WORLD_VERSION && defined EIGEN_GEOMETRY_MODULE_H
276
Affine3(
const
Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)>& affine);
277
Affine3(
const
Eigen::Transform<T, 3, Eigen::Affine>& affine);
278
operator
Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)>()
const;
279
operator
Eigen::Transform<T, 3, Eigen::Affine>()
const;
283
template<
typename
T>
static
284
Affine3<T> operator*(
const
Affine3<T>& affine1,
const
Affine3<T>& affine2);
287
template<
typename
T,
typename
V>
static
288
V operator*(
const
Affine3<T>& affine,
const
V& vector);
290
typedef
Affine3<float> Affine3f;
291
typedef
Affine3<double> Affine3d;
293
static
Vec3f operator*(
const
Affine3f& affine,
const
Vec3f& vector);
294
static
Vec3d operator*(
const
Affine3d& affine,
const
Vec3d& vector);
296
template<
typename
_Tp>
class
DataType< Affine3<_Tp> >
299
typedef
Affine3<_Tp> value_type;
300
typedef
Affine3<typename DataType<_Tp>::work_type> work_type;
301
typedef
_Tp channel_type;
303
enum
{ generic_type = 0,
305
fmt = traits::SafeFmt<channel_type>::fmt + ((channels - 1) << 8)
306
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
307
,depth = DataType<channel_type>::depth
308
,type = CV_MAKETYPE(depth, channels)
312
typedef
Vec<channel_type, channels> vec_type;
316
template<
typename
_Tp>
317
struct
Depth< Affine3<_Tp> > {
enum
{ value = Depth<_Tp>::value }; };
318
template<
typename
_Tp>
319
struct
Type< Affine3<_Tp> > {
enum
{ value = CV_MAKETYPE(Depth<_Tp>::value, 16) }; };
331
template<
typename
T>
inline
332cv::Affine3<T>::Affine3()
333
: matrix(Mat4::eye())
336
template<
typename
T>
inline
337cv::Affine3<T>::Affine3(
const
Mat4& affine)
341
template<
typename
T>
inline
342cv::Affine3<T>::Affine3(
const
Mat3& R,
const
Vec3& t)
346
matrix.val[12] = matrix.val[13] = matrix.val[14] = 0;
350
template<
typename
T>
inline
351cv::Affine3<T>::Affine3(
const
Vec3& _rvec,
const
Vec3& t)
355
matrix.val[12] = matrix.val[13] = matrix.val[14] = 0;
359
template<
typename
T>
inline
360cv::Affine3<T>::Affine3(
const
cv::Mat& data,
const
Vec3& t)
365
if
(data.cols == 4 && data.rows == 4)
370
else
if
(data.cols == 4 && data.rows == 3)
372
rotation(data(Rect(0, 0, 3, 3)));
373
translation(data(Rect(3, 0, 1, 3)));
381
matrix.val[12] = matrix.val[13] = matrix.val[14] = 0;
385
template<
typename
T>
inline
386cv::Affine3<T>::Affine3(
const
float_type* vals) : matrix(vals)
389
template<
typename
T>
inline
390cv::Affine3<T> cv::Affine3<T>::Identity()
392
return
Affine3<T>(cv::Affine3<T>::Mat4::eye());
395
template<
typename
T>
inline
396
void
cv::Affine3<T>::rotation(
const
Mat3& R)
401
template<
typename
T>
inline
402
void
cv::Affine3<T>::rotation(
const
Vec3& _rvec)
404
double
theta =
norm(_rvec);
406
if
(theta < DBL_EPSILON)
407
rotation(Mat3::eye());
413
double
itheta = (theta != 0) ? 1./theta : 0.;
415
Point3_<T> r = _rvec*itheta;
417
Mat3 rrt( r.x*r.x, r.x*r.y, r.x*r.z, r.x*r.y, r.y*r.y, r.y*r.z, r.x*r.z, r.y*r.z, r.z*r.z );
418
Mat3 r_x( 0, -r.z, r.y, r.z, 0, -r.x, -r.y, r.x, 0 );
422
Mat3 R = c*Mat3::eye() + c1*rrt + s*r_x;
429
template<
typename
T>
inline
430
void
cv::Affine3<T>::rotation(
const
cv::Mat& data)
435
if
(data.cols == 3 && data.rows == 3)
441
else
if
((data.cols == 3 && data.rows == 1) || (data.cols == 1 && data.rows == 3))
444
data.reshape(1, 3).copyTo(_rvec);
448
CV_Error(Error::StsError,
"Input matrix can only be 3x3, 1x3 or 3x1");
451
template<
typename
T>
inline
452
void
cv::Affine3<T>::linear(
const
Mat3& L)
454
matrix.val[0] = L.val[0]; matrix.val[1] = L.val[1]; matrix.val[ 2] = L.val[2];
455
matrix.val[4] = L.val[3]; matrix.val[5] = L.val[4]; matrix.val[ 6] = L.val[5];
456
matrix.val[8] = L.val[6]; matrix.val[9] = L.val[7]; matrix.val[10] = L.val[8];
459
template<
typename
T>
inline
460
void
cv::Affine3<T>::translation(
const
Vec3& t)
462
matrix.val[3] = t[0]; matrix.val[7] = t[1]; matrix.val[11] = t[2];
465
template<
typename
T>
inline
466
typename
cv::Affine3<T>::Mat3 cv::Affine3<T>::rotation()
const
471
template<
typename
T>
inline
472
typename
cv::Affine3<T>::Mat3 cv::Affine3<T>::linear()
const
474
typename
cv::Affine3<T>::Mat3 R;
475
R.val[0] = matrix.val[0]; R.val[1] = matrix.val[1]; R.val[2] = matrix.val[ 2];
476
R.val[3] = matrix.val[4]; R.val[4] = matrix.val[5]; R.val[5] = matrix.val[ 6];
477
R.val[6] = matrix.val[8]; R.val[7] = matrix.val[9]; R.val[8] = matrix.val[10];
481
template<
typename
T>
inline
482
typename
cv::Affine3<T>::Vec3 cv::Affine3<T>::translation()
const
484
return
Vec3(matrix.val[3], matrix.val[7], matrix.val[11]);
487
template<
typename
T>
inline
488
typename
cv::Affine3<T>::Vec3 cv::Affine3<T>::rvec()
const
495
double
rx = R.val[7] - R.val[5];
496
double
ry = R.val[2] - R.val[6];
497
double
rz = R.val[3] - R.val[1];
499
double
s =
std::sqrt((rx*rx + ry*ry + rz*rz)*0.25);
500
double
c = (R.val[0] + R.val[4] + R.val[8] - 1) * 0.5;
501
c = c > 1.0 ? 1.0 : c < -1.0 ? -1.0 : c;
511
t = (R.val[0] + 1) * 0.5;
513
t = (R.val[4] + 1) * 0.5;
515
t = (R.val[8] + 1) * 0.5;
518
if( fabs(rx) < fabs(ry) && fabs(rx) < fabs(rz) && (R.val[5] > 0) != (ry*rz > 0) )
520
theta /=
std::sqrt(rx*rx + ry*ry + rz*rz);
528
double
vth = 1/(2*s);
530
rx *= vth; ry *= vth; rz *= vth;
536
template<
typename
T>
inline
539
return
matrix.inv(method);
542
template<
typename
T>
inline
546
Vec3 tc = translation();
548
result.val[12] = result.val[13] = result.val[14] = 0;
551
for(
int
j = 0; j < 3; ++j)
553
for(
int
i = 0; i < 3; ++i)
555
float_type value = 0;
556
for(
int
k = 0; k < 3; ++k)
557
value += R(j, k) * Lc(k, i);
558
result(j, i) = value;
561
result(j, 3) = R.row(j).dot(tc.t());
566
template<
typename
T>
inline
569
return
rotate(Affine3f(_rvec).rotation());
572
template<
typename
T>
inline
573cv::Affine3<T> cv::Affine3<T>::translate(
const
Vec3& t)
const
582
template<
typename
T>
inline
583cv::Affine3<T> cv::Affine3<T>::concatenate(
const
Affine3<T>& affine)
const
585
return
(*this).rotate(affine.rotation()).translate(affine.translation());
588
template<
typename
T>
template
<
typename
Y>
inline
589cv::Affine3<T>::operator Affine3<Y>()
const
591
return
Affine3<Y>(matrix);
594
template<
typename
T>
template
<
typename
Y>
inline
595cv::Affine3<Y> cv::Affine3<T>::cast()
const
597
return
Affine3<Y>(matrix);
600
template<
typename
T>
inline
601cv::Affine3<T> cv::operator*(
const
cv::Affine3<T>& affine1,
const
cv::Affine3<T>& affine2)
603
return
affine2.concatenate(affine1);
606
template<
typename
T,
typename
V>
inline
607V cv::operator*(
const
cv::Affine3<T>& affine,
const
V& v)
609
const
typename
Affine3<T>::Mat4& m = affine.matrix;
612
r.x = m.val[0] * v.x + m.val[1] * v.y + m.val[ 2] * v.z + m.val[ 3];
613
r.y = m.val[4] * v.x + m.val[5] * v.y + m.val[ 6] * v.z + m.val[ 7];
614
r.z = m.val[8] * v.x + m.val[9] * v.y + m.val[10] * v.z + m.val[11];
623
r.val[0] = m.val[0] * v[0] + m.val[1] * v[1] + m.val[ 2] * v[2] + m.val[ 3];
624
r.val[1] = m.val[4] * v[0] + m.val[5] * v[1] + m.val[ 6] * v[2] + m.val[ 7];
625
r.val[2] = m.val[8] * v[0] + m.val[9] * v[1] + m.val[10] * v[2] + m.val[11];
634
r.val[0] = m.val[0] * v[0] + m.val[1] * v[1] + m.val[ 2] * v[2] + m.val[ 3];
635
r.val[1] = m.val[4] * v[0] + m.val[5] * v[1] + m.val[ 6] * v[2] + m.val[ 7];
636
r.val[2] = m.val[8] * v[0] + m.val[9] * v[1] + m.val[10] * v[2] + m.val[11];
642
#if defined EIGEN_WORLD_VERSION && defined EIGEN_GEOMETRY_MODULE_H
644
template<
typename
T>
inline
645cv::Affine3<T>::Affine3(
const
Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)>& affine)
650
template<
typename
T>
inline
651cv::Affine3<T>::Affine3(
const
Eigen::Transform<T, 3, Eigen::Affine>& affine)
653
Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)> a = affine;
657
template<
typename
T>
inline
658cv::Affine3<T>::operator Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)>()
const
660
Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)> r;
666
template<
typename
T>
inline
667cv::Affine3<T>::operator Eigen::Transform<T, 3, Eigen::Affine>()
const
669
return
this->
operator
Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)>();
n-dimensional dense array class
Definition:
mat.hpp:802
void copyTo(OutputArray m) const
Copies the matrix to another one.
Template class for small matrices whose type and size are known at compilation time
Definition:
matx.hpp:100
@ FULL_UV
Definition:
core.hpp:2656
@ MODIFY_A
Definition:
core.hpp:2649
static void compute(InputArray src, OutputArray w, OutputArray u, OutputArray vt, int flags=0)
decomposes matrix and stores the results to user-provided matrices
Template class for short numerical vectors, a partial case of Matx
Definition:
matx.hpp:342
CV_EXPORTS_W void max(InputArray src1, InputArray src2, OutputArray dst)
Calculates per-element maximum of two arrays or an array and a scalar.
CV_EXPORTS_W void sqrt(InputArray src, OutputArray dst)
Calculates a square root of array elements.
CV_EXPORTS_W double norm(InputArray src1, int normType=NORM_L2, InputArray mask=noArray())
Calculates the absolute norm of an array.
CV_EXPORTS_W void rotate(InputArray src, OutputArray dst, int rotateCode)
Rotates a 2D array in multiples of 90 degrees. The function cv::rotate rotates the array in one of th...
@ DECOMP_SVD
Definition:
base.hpp:138
#define CV_Error(code, msg)
Call the error handler.
Definition:
base.hpp:320
#define CV_Assert(expr)
Checks a condition at runtime and throws exception if it fails
Definition:
base.hpp:342
Quat< T > inv(const Quat< T > &q, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT)
Quat< T > cos(const Quat< T > &q)
Quat< T > sin(const Quat< T > &q)
Quat< T > acos(const Quat< T > &q)
"black box" representation of the file storage associated with a file on disk.
Definition:
aruco.hpp:75
DualQuat< T > inv(const DualQuat< T > &dq, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT)
Definition:
dualquaternion.inl.hpp:187
Definition:
traits.hpp:386