22 #ifndef OV_CORE_FEATURE_HELPER_H
23 #define OV_CORE_FEATURE_HELPER_H
25 #include <Eigen/Eigen>
60 static void compute_disparity(std::shared_ptr<ov_core::FeatureDatabase> db,
double time0,
double time1,
double &disp_mean,
61 double &disp_var,
int &total_feats) {
64 std::vector<std::shared_ptr<Feature>> feats0 = db->features_containing(time0,
false,
true);
67 std::vector<double> disparities;
68 for (
auto &feat : feats0) {
71 for (
auto &campairs : feat->timestamps) {
74 size_t camid = campairs.first;
75 auto it0 = std::find(feat->timestamps.at(camid).begin(), feat->timestamps.at(camid).end(), time0);
76 auto it1 = std::find(feat->timestamps.at(camid).begin(), feat->timestamps.at(camid).end(), time1);
77 if (it0 == feat->timestamps.at(camid).end() || it1 == feat->timestamps.at(camid).end())
79 auto idx0 = std::distance(feat->timestamps.at(camid).begin(), it0);
80 auto idx1 = std::distance(feat->timestamps.at(camid).begin(), it1);
83 Eigen::Vector2f uv0 = feat->uvs.at(camid).at(idx0).block(0, 0, 2, 1);
84 Eigen::Vector2f uv1 = feat->uvs.at(camid).at(idx1).block(0, 0, 2, 1);
85 disparities.push_back((uv1 - uv0).norm());
90 if (disparities.size() < 2) {
98 for (
double disp_i : disparities) {
101 disp_mean /= (double)disparities.size();
103 for (
double &disp_i : disparities) {
104 disp_var += std::pow(disp_i - disp_mean, 2);
106 disp_var = std::sqrt(disp_var / (
double)(disparities.size() - 1));
107 total_feats = (int)disparities.size();
123 static void compute_disparity(std::shared_ptr<ov_core::FeatureDatabase> db,
double &disp_mean,
double &disp_var,
int &total_feats,
124 double newest_time = -1,
double oldest_time = -1) {
127 std::vector<double> disparities;
128 for (
auto &feat : db->get_internal_data()) {
129 for (
auto &campairs : feat.second->timestamps) {
132 if (campairs.second.size() < 2)
136 size_t camid = campairs.first;
139 Eigen::Vector2f uv0 = Eigen::Vector2f::Zero();
140 Eigen::Vector2f uv1 = Eigen::Vector2f::Zero();
141 for (
size_t idx = 0; idx < feat.second->timestamps.at(camid).size(); idx++) {
142 double time = feat.second->timestamps.at(camid).at(idx);
143 if ((oldest_time == -1 || time > oldest_time) && !found0) {
144 uv0 = feat.second->uvs.at(camid).at(idx).block(0, 0, 2, 1);
148 if ((newest_time == -1 || time < newest_time) && found0) {
149 uv1 = feat.second->uvs.at(camid).at(idx).block(0, 0, 2, 1);
156 if (!found0 || !found1)
158 disparities.push_back((uv1 - uv0).norm());
163 if (disparities.size() < 2) {
171 for (
double disp_i : disparities) {
174 disp_mean /= (double)disparities.size();
176 for (
double &disp_i : disparities) {
177 disp_var += std::pow(disp_i - disp_mean, 2);
179 disp_var = std::sqrt(disp_var / (
double)(disparities.size() - 1));
180 total_feats = (int)disparities.size();