examples/coordinates/Main.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <memory>
3 #include <tuple>
4 #include <stdlib.h>
5 
6 #include <boost/optional.hpp>
7 
8 // lvr2 includes
11 
12 int main(int argc, char** argv)
13 {
14  std::cout << "Coordinate Example" << std::endl;
15  // Overview Coordinate Systems
16 
44  // x: 2.0, y: 0.5, z: 1.0
45  // front: 1.0, right: 2.0, down: 0.5
46  lvr2::Vector3d cv_point = {2.0, 0.5, 1.0};
47  std::cout << "cv point: " << cv_point.transpose() << std::endl;
48 
49  // convert to lvr
50  // should be x(front): 1.0, y(left): -2.0, z(up): -0.5
51  lvr2::Vector3d lvr_point = lvr2::openCvToLvr(cv_point);
52  std::cout << "lvr point: " << lvr_point.transpose() << std::endl;
53 
54  if(lvr2::lvrToOpenCv(lvr_point) == cv_point)
55  {
56  std::cout << "LVR <-> OpenCV - Point: Success" << std::endl;
57  }
58 
59  // check opencv transformation
60 
61  lvr2::Rotationd cv_rot, lvr_rot;
62 
63  double roll = -0.25*M_PI; // cv: z, lvr: x
64  double pitch = 1.6*M_PI; // cv: -x, lvr: y
65  double yaw = -0.06*M_PI; // cv: -y, lvr: z
66 
67  // cv rotate x: pitch
68  cv_rot = Eigen::AngleAxisd(roll, Eigen::Vector3d::UnitZ())
69  * Eigen::AngleAxisd(-pitch, Eigen::Vector3d::UnitX())
70  * Eigen::AngleAxisd(-yaw, Eigen::Vector3d::UnitY());
71 
72  // cv -> lvr
73  lvr_rot = lvr2::openCvToLvr(cv_rot);
74 
75 
76  // cv_rot
77 
78  lvr2::Vector3d cv_point_rotated = cv_rot * cv_point;
79  lvr2::Vector3d lvr_point_rotated = lvr_rot * lvr_point;
80 
81  // lvr2::openCvToLvr(cv_point_rotated) - lvr_point_rotated
82  if((lvr2::openCvToLvr(cv_point_rotated) - lvr_point_rotated).norm() < 0.000001)
83  {
84  std::cout << "LVR <-> OpenCV - Rotation Matrix: Success" << std::endl;
85  } else {
86  std::cout << "LVR <-> OpenCV - Rotation Matrix: Wrong" << std::endl;
87  }
88 
89  // transformation
90  lvr2::Transformd cv_transform, lvr_transform;
91 
92  cv_transform = lvr2::Transformd::Identity();
93  cv_transform.block<3,3>(0,0) = cv_rot;
94  cv_transform(0,2) = 2.0;
95  cv_transform(1,2) = 5.0;
96  cv_transform(2,2) = -1.0;
97 
98  lvr_transform = lvr2::openCvToLvr(cv_transform);
99 
100  lvr2::Vector3d cv_point_transformed = cv_transform * cv_point;
101  lvr2::Vector3d lvr_point_transformed = lvr_transform * lvr_point;
102 
103  if((lvr2::openCvToLvr(cv_point_transformed)-lvr_point_transformed).norm() < 0.000001)
104  {
105  std::cout << "LVR <-> OpenCV - Transformation Matrix: Success" << std::endl;
106  } else {
107  std::cout << "LVR <-> OpenCV - Transformation Matrix: Wrong" << std::endl;
108  }
109 
110  return 0;
111 }
lvr2::Transformd
Transform< double > Transformd
4x4 double precision transformation matrix
Definition: MatrixTypes.hpp:71
M_PI
#define M_PI
Definition: Matrix4.hpp:52
main
int main(int argc, char **argv)
Definition: examples/coordinates/Main.cpp:12
MatrixTypes.hpp
lvr2::Vector3d
Eigen::Vector3d Vector3d
Eigen 3D vector, double precision.
Definition: MatrixTypes.hpp:121
argc
int argc
Definition: tests_high_five_parallel.cpp:27
lvr2::openCvToLvr
static Vector3< T > openCvToLvr(const Vector3< T > &in)
OpenCV to Lvr coordinate change: Point.
Definition: TransformUtils.hpp:364
kfusion::device::norm
__kf_device__ float norm(const float3 &v)
Definition: temp_utils.hpp:87
argv
char ** argv
Definition: tests_high_five_parallel.cpp:28
lvr2::lvrToOpenCv
static Vector3< T > lvrToOpenCv(const Vector3< T > &in)
Lvr to OpenCV coordinate change: Point.
Definition: TransformUtils.hpp:538
lvr2::Rotationd
Rotation< double > Rotationd
Double precision 3x3 rotation matrix.
Definition: MatrixTypes.hpp:81
TransformUtils.hpp


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Wed Mar 2 2022 00:37:24