Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
d02ecff8
Commit
d02ecff8
authored
May 11, 2018
by
catree
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clarify the Euler angles convention chosen. Replace rotation inverse with matrix transpose.
parent
df02fe06
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
23 deletions
+29
-23
Utils.cpp
...rial_code/calib3d/real_time_pose_estimation/src/Utils.cpp
+29
-23
No files found.
samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/Utils.cpp
View file @
d02ecff8
...
@@ -179,13 +179,16 @@ double get_translation_error(const cv::Mat &t_true, const cv::Mat &t)
...
@@ -179,13 +179,16 @@ double get_translation_error(const cv::Mat &t_true, const cv::Mat &t)
double
get_rotation_error
(
const
cv
::
Mat
&
R_true
,
const
cv
::
Mat
&
R
)
double
get_rotation_error
(
const
cv
::
Mat
&
R_true
,
const
cv
::
Mat
&
R
)
{
{
cv
::
Mat
error_vec
,
error_mat
;
cv
::
Mat
error_vec
,
error_mat
;
error_mat
=
R_true
*
cv
::
Mat
(
R
.
inv
()).
mul
(
-
1
);
error_mat
=
-
R_true
*
R
.
t
(
);
cv
::
Rodrigues
(
error_mat
,
error_vec
);
cv
::
Rodrigues
(
error_mat
,
error_vec
);
return
cv
::
norm
(
error_vec
);
return
cv
::
norm
(
error_vec
);
}
}
// Converts a given Rotation Matrix to Euler angles
// Converts a given Rotation Matrix to Euler angles
// Convention used is Y-Z-X Tait-Bryan angles
// Reference code implementation:
// https://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToEuler/index.htm
cv
::
Mat
rot2euler
(
const
cv
::
Mat
&
rotationMatrix
)
cv
::
Mat
rot2euler
(
const
cv
::
Mat
&
rotationMatrix
)
{
{
cv
::
Mat
euler
(
3
,
1
,
CV_64F
);
cv
::
Mat
euler
(
3
,
1
,
CV_64F
);
...
@@ -198,49 +201,52 @@ cv::Mat rot2euler(const cv::Mat & rotationMatrix)
...
@@ -198,49 +201,52 @@ cv::Mat rot2euler(const cv::Mat & rotationMatrix)
double
m20
=
rotationMatrix
.
at
<
double
>
(
2
,
0
);
double
m20
=
rotationMatrix
.
at
<
double
>
(
2
,
0
);
double
m22
=
rotationMatrix
.
at
<
double
>
(
2
,
2
);
double
m22
=
rotationMatrix
.
at
<
double
>
(
2
,
2
);
double
x
,
y
,
z
;
double
bank
,
attitude
,
heading
;
// Assuming the angles are in radians.
// Assuming the angles are in radians.
if
(
m10
>
0.998
)
{
// singularity at north pole
if
(
m10
>
0.998
)
{
// singularity at north pole
x
=
0
;
bank
=
0
;
y
=
CV_PI
/
2
;
attitude
=
CV_PI
/
2
;
z
=
atan2
(
m02
,
m22
);
heading
=
atan2
(
m02
,
m22
);
}
}
else
if
(
m10
<
-
0.998
)
{
// singularity at south pole
else
if
(
m10
<
-
0.998
)
{
// singularity at south pole
x
=
0
;
bank
=
0
;
y
=
-
CV_PI
/
2
;
attitude
=
-
CV_PI
/
2
;
z
=
atan2
(
m02
,
m22
);
heading
=
atan2
(
m02
,
m22
);
}
}
else
else
{
{
x
=
atan2
(
-
m12
,
m11
);
bank
=
atan2
(
-
m12
,
m11
);
y
=
asin
(
m10
);
attitude
=
asin
(
m10
);
z
=
atan2
(
-
m20
,
m00
);
heading
=
atan2
(
-
m20
,
m00
);
}
}
euler
.
at
<
double
>
(
0
)
=
x
;
euler
.
at
<
double
>
(
0
)
=
bank
;
euler
.
at
<
double
>
(
1
)
=
y
;
euler
.
at
<
double
>
(
1
)
=
attitude
;
euler
.
at
<
double
>
(
2
)
=
z
;
euler
.
at
<
double
>
(
2
)
=
heading
;
return
euler
;
return
euler
;
}
}
// Converts a given Euler angles to Rotation Matrix
// Converts a given Euler angles to Rotation Matrix
// Convention used is Y-Z-X Tait-Bryan angles
// Reference:
// https://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToMatrix/index.htm
cv
::
Mat
euler2rot
(
const
cv
::
Mat
&
euler
)
cv
::
Mat
euler2rot
(
const
cv
::
Mat
&
euler
)
{
{
cv
::
Mat
rotationMatrix
(
3
,
3
,
CV_64F
);
cv
::
Mat
rotationMatrix
(
3
,
3
,
CV_64F
);
double
x
=
euler
.
at
<
double
>
(
0
);
double
bank
=
euler
.
at
<
double
>
(
0
);
double
y
=
euler
.
at
<
double
>
(
1
);
double
attitude
=
euler
.
at
<
double
>
(
1
);
double
z
=
euler
.
at
<
double
>
(
2
);
double
heading
=
euler
.
at
<
double
>
(
2
);
// Assuming the angles are in radians.
// Assuming the angles are in radians.
double
ch
=
cos
(
z
);
double
ch
=
cos
(
heading
);
double
sh
=
sin
(
z
);
double
sh
=
sin
(
heading
);
double
ca
=
cos
(
y
);
double
ca
=
cos
(
attitude
);
double
sa
=
sin
(
y
);
double
sa
=
sin
(
attitude
);
double
cb
=
cos
(
x
);
double
cb
=
cos
(
bank
);
double
sb
=
sin
(
x
);
double
sb
=
sin
(
bank
);
double
m00
,
m01
,
m02
,
m10
,
m11
,
m12
,
m20
,
m21
,
m22
;
double
m00
,
m01
,
m02
,
m10
,
m11
,
m12
,
m20
,
m21
,
m22
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment