NDEVR
API Documentation
GeometricTools.h
1#pragma once
2#include <opencv2/core/core.hpp>
3#include <OrbSLAM/Thirdparty/Sophus/sophus/se3.hpp>
4#include <Eigen/Core>
5
6namespace NDEVR
7{
8 class KeyFrame;
15 {
16 public:
17 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
23 static Eigen::Matrix3f ComputeF12(KeyFrame*& pKF1, KeyFrame*& pKF2);
24
33 static bool Triangulate(Eigen::Vector3f& x_c1, Eigen::Vector3f& x_c2, Eigen::Matrix<float, 3, 4>& Tc1w, Eigen::Matrix<float, 3, 4>& Tc2w, Eigen::Vector3f& x3D);
34
40 template<int rows, int cols>
41 static bool CheckMatrices(const cv::Mat& cvMat, const Eigen::Matrix<float, rows, cols>& eigMat) {
42 const float epsilon = 1e-3;
43 // std::cout << cvMat.cols - cols << cvMat.rows - rows << std::endl;
44 if (rows != cvMat.rows || cols != cvMat.cols) {
45 //std::cout << "wrong cvmat size\n";
46 return false;
47 }
48 for (int i = 0; i < rows; i++)
49 for (int j = 0; j < cols; j++)
50 if ((cvMat.at<float>(i, j) > (eigMat(i, j) + epsilon)) ||
51 (cvMat.at<float>(i, j) < (eigMat(i, j) - epsilon)))
52 {
53 //std::cout << "cv mat:\n" << cvMat << std::endl;
54 //std::cout << "eig mat:\n" << eigMat << std::endl;
55 return false;
56 }
57 return true;
58 }
59
65 template<typename T, int rows, int cols>
66 static bool CheckMatrices(const Eigen::Matrix<T, rows, cols>& eigMat1, const Eigen::Matrix<T, rows, cols>& eigMat2) {
67 const float epsilon = 1e-3;
68 for (int i = 0; i < rows; i++)
69 for (int j = 0; j < cols; j++)
70 if ((eigMat1(i, j) > (eigMat2(i, j) + epsilon)) ||
71 (eigMat1(i, j) < (eigMat2(i, j) - epsilon)))
72 {
73 //std::cout << "eig mat 1:\n" << eigMat1 << std::endl;
74 //std::cout << "eig mat 2:\n" << eigMat2 << std::endl;
75 return false;
76 }
77 return true;
78 }
79 };
80}
Utility class for geometric computations between keyframes.
static bool CheckMatrices(const Eigen::Matrix< T, rows, cols > &eigMat1, const Eigen::Matrix< T, rows, cols > &eigMat2)
Checks whether two Eigen matrices are approximately equal.
static EIGEN_MAKE_ALIGNED_OPERATOR_NEW Eigen::Matrix3f ComputeF12(KeyFrame *&pKF1, KeyFrame *&pKF2)
Computes the fundamental matrix between two keyframes.
static bool CheckMatrices(const cv::Mat &cvMat, const Eigen::Matrix< float, rows, cols > &eigMat)
Checks whether an OpenCV matrix and Eigen matrix are approximately equal.
static bool Triangulate(Eigen::Vector3f &x_c1, Eigen::Vector3f &x_c2, Eigen::Matrix< float, 3, 4 > &Tc1w, Eigen::Matrix< float, 3, 4 > &Tc2w, Eigen::Vector3f &x3D)
Triangulates a 3D point from two camera observations.
A keyframe in the SLAM map, derived from Frame.
Definition KeyFrame.h:31
The primary namespace for the NDEVR SDK.