licornea_tools
eigen.h
Go to the documentation of this file.
1 #ifndef LICORNEA_EIGEN_H_
2 #define LICORNEA_EIGEN_H_
3 
4 #include "common.h"
5 #include <Eigen/Core>
6 #include <Eigen/Eigen>
7 #include <opencv2/core/eigen.hpp>
8 
9 namespace tlz {
10 
11 using Eigen_matXX = Eigen::Matrix<real, Eigen::Dynamic, Eigen::Dynamic>;
12 template<std::size_t Cols> using Eigen_matXn = Eigen::Matrix<real, Eigen::Dynamic, Cols>;
13 template<std::size_t Rows> using Eigen_matnX = Eigen::Matrix<real, Rows, Eigen::Dynamic>;
14 template<std::size_t Rows, std::size_t Cols> using Eigen_mat = Eigen::Matrix<real, Rows, Cols>;
17 
18 using Eigen_vecX = Eigen::Matrix<real, Eigen::Dynamic, 1>;
19 template<std::size_t Rows> using Eigen_vec = Eigen::Matrix<real, Rows, 1>;
22 
23 template<int Rows, int Cols>
24 Eigen_mat<Rows, Cols> to_eigen_mat(const cv::Matx<real, Rows, Cols>& cv_mat) {
25  Eigen_mat<Rows, Cols> eigen_mat;
26  for(std::ptrdiff_t i = 0; i < Rows; ++i) for(std::ptrdiff_t j = 0; j < Cols; ++j) eigen_mat(i, j) = cv_mat(i, j);
27  return eigen_mat;
28 }
29 template<int Rows>
30 Eigen_vec<Rows> to_eigen(const cv::Vec<real, Rows>& cv_vec) {
31  Eigen_vec<Rows> eigen_vec;
32  for(std::ptrdiff_t i = 0; i < Rows; ++i) eigen_vec[i] = cv_vec[i];
33  return eigen_vec;
34 }
35 
36 
37 
38 template<std::size_t Rows, std::size_t Cols>
39 cv::Matx<real, Rows, Cols> from_eigen_mat(const Eigen_mat<Rows, Cols>& eigen_mat) {
40  cv::Matx<real, Rows, Cols> cv_mat;
41  for(std::ptrdiff_t i = 0; i < Rows; ++i) for(std::ptrdiff_t j = 0; j < Cols; ++j) cv_mat(i, j) = eigen_mat(i, j);
42  return cv_mat;
43 }
44 template<int Rows>
45 cv::Vec<real, Rows> from_eigen(const Eigen_vec<Rows>& eigen_vec) {
46  cv::Vec<real, Rows> cv_vec;
47  for(std::ptrdiff_t i = 0; i < Rows; ++i) cv_vec[i] = eigen_vec[i];
48  return cv_vec;
49 }
50 
51 
52 }
53 
54 #endif
Eigen::Matrix< real, Rows, Cols > Eigen_mat
Definition: eigen.h:14
cv::Vec< real, Rows > from_eigen(const Eigen_vec< Rows > &eigen_vec)
Definition: eigen.h:45
Eigen::Matrix< real, Eigen::Dynamic, Eigen::Dynamic > Eigen_matXX
Definition: eigen.h:11
Eigen::Matrix< real, Rows, 1 > Eigen_vec
Definition: eigen.h:19
Eigen_mat< 2, 2 > Eigen_mat22
Definition: eigen.h:16
Eigen_vec< 3 > Eigen_vec3
Definition: eigen.h:20
Eigen_mat< Rows, Cols > to_eigen_mat(const cv::Matx< real, Rows, Cols > &cv_mat)
Definition: eigen.h:24
Eigen::Matrix< real, Eigen::Dynamic, 1 > Eigen_vecX
Definition: eigen.h:18
Eigen::Matrix< real, Rows, Eigen::Dynamic > Eigen_matnX
Definition: eigen.h:13
Eigen::Matrix< real, Eigen::Dynamic, Cols > Eigen_matXn
Definition: eigen.h:12
Eigen_vec< Rows > to_eigen(const cv::Vec< real, Rows > &cv_vec)
Definition: eigen.h:30
cv::Matx< real, Rows, Cols > from_eigen_mat(const Eigen_mat< Rows, Cols > &eigen_mat)
Definition: eigen.h:39
Eigen_mat< 3, 3 > Eigen_mat33
Definition: eigen.h:15
Eigen_vec< 2 > Eigen_vec2
Definition: eigen.h:21