18 #ifndef VISION_COMMON_UTILITIES_H_
19 #define VISION_COMMON_UTILITIES_H_
25 #include <Eigen/Geometry>
27 #include <gtsam/base/Matrix.h>
29 #include <opencv2/core/eigen.hpp>
30 #include <opencv2/opencv.hpp>
37 const Eigen::Matrix<T, 3, 3>& intrinsics);
40 const Eigen::Matrix<T, 3, 3>& intrinsics);
43 gtsam::OptionalJacobian<3, 1> d_backprojected_point_d_depth = boost::none);
45 Eigen::Vector2d
FocalLengths(
const Eigen::Matrix3d& intrinsics);
50 gtsam::OptionalJacobian<2, 3> d_projected_point_d_cam_t_point = boost::none);
52 template <
typename DISTORTER>
54 const Eigen::VectorXd& distortion_params);
65 template <
typename FeatureTracksMapType>
66 bool Standstill(
const FeatureTracksMapType& feature_tracks,
const StandstillParams& params);
71 const Eigen::Matrix<T, 3, 3>& intrinsics) {
72 const T& f_x = intrinsics(0, 0);
73 const T& f_y = intrinsics(1, 1);
74 const T& p_x = intrinsics(0, 2);
75 const T& p_y = intrinsics(1, 2);
77 const T& x = absolute_point[0];
78 const T& y = absolute_point[1];
79 const T relative_x = (x - p_x) / f_x;
80 const T relative_y = (y - p_y) / f_y;
81 return Eigen::Matrix<T, 2, 1>(relative_x, relative_y);
86 const Eigen::Matrix<T, 3, 3>& intrinsics) {
87 const T& f_x = intrinsics(0, 0);
88 const T& f_y = intrinsics(1, 1);
89 const T& p_x = intrinsics(0, 2);
90 const T& p_y = intrinsics(1, 2);
91 return Eigen::Matrix<T, 2, 1>(relative_point[0] * f_x + p_x, relative_point[1] * f_y + p_y);
94 template <
typename DISTORTER>
96 const Eigen::VectorXd& distortion_params) {
97 const Eigen::Vector2d undistorted_image_point =
Project(cam_t_point, intrinsics);
98 const DISTORTER distorter;
99 return distorter.Distort(distortion_params, intrinsics, undistorted_image_point);
102 template <
typename FeatureTracksMapType>
104 if (feature_tracks.empty())
return false;
105 const auto& latest = feature_tracks.cbegin()->second.Latest();
106 if (!latest)
return false;
109 double total_average_distance_from_mean = 0;
110 int num_valid_feature_tracks = 0;
111 for (
const auto& feature_track : feature_tracks) {
113 const double average_distance_from_mean =
117 total_average_distance_from_mean += average_distance_from_mean;
118 ++num_valid_feature_tracks;
122 double average_distance_from_mean = 0;
123 if (num_valid_feature_tracks > 0)
124 average_distance_from_mean = total_average_distance_from_mean / num_valid_feature_tracks;
130 #endif // VISION_COMMON_UTILITIES_H_