Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #define _USE_MATH_DEFINES
  2. #include <opencv2/opencv.hpp>
  3. #include <Eigen/Geometry>
  4. #include <dlib/matrix.h>
  5. #include <dlib/opencv.h>
  6. #include <dlib/image_transforms.h>
  7.  
  8. using namespace cv;
  9.  
  10. int main(int argc, char **argv)
  11. {
  12. // Set up a movement
  13. Eigen::Matrix4d M1;
  14. M1 << 1, 0, 0, 0, //
  15. 0, 1, 0, 0, //
  16. 0, 0, 1, 0, //
  17. 0, 0, 0, 1;
  18.  
  19. Eigen::Matrix4d M2;
  20. double theta = M_PI / 2;
  21. M2 << cos(theta), -sin(theta), 0, 0, //
  22. sin(theta), cos(theta), 0, 0, //
  23. 0, 0, 1, 1, //
  24. 0, 0, 0, 1;
  25.  
  26. Eigen::Affine3d T1(M1);
  27. Eigen::Affine3d T2(M2);
  28.  
  29. // Compute essential
  30. Eigen::Affine3d T_CW = T2.inverse() * T1;
  31. Eigen::Vector3d t = T_CW.translation();
  32. Eigen::Matrix3d R = T_CW.rotation();
  33.  
  34. std::cout << "delta transform" << std::endl;
  35. std::cout << dlib::mat(t) << std::endl;
  36. std::cout << dlib::mat(R) << std::endl;
  37.  
  38. Mat tx;
  39. tx = (Mat_<double>(3, 3) << 0, -t(2), t(1), //
  40. t(2), 0, -t(0), //
  41. -t(1), t(0), 0);
  42.  
  43. Mat Rx = (Mat_<double>(3, 3) << R(0, 0), R(0, 1), R(0, 2), //
  44. R(1, 0), R(1, 1), R(1, 2), //
  45. R(2, 0), R(2, 1), R(2, 2));
  46.  
  47. Mat E = tx * Rx;
  48. dlib::array2d<double> E_tmp;
  49. //dlib::assign_image(E_tmp, E);
  50.  
  51. //std::cout << "E" << std::endl << mat(E_tmp) << std::endl;
  52.  
  53. // recover essential
  54. Mat R1;
  55. Mat R2;
  56. Mat tcv;
  57. decomposeEssentialMat(E, R1, R2, tcv);
  58.  
  59. std::cout << "decomposed matrix" << std::endl;
  60. std::cout << "R1" << std::endl << R1 << std::endl;
  61. std::cout << "R2" << std::endl << R2 << std::endl;
  62. std::cout << "t" << std::endl << tcv << std::endl;
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement