src/frontend/StereoFrame.cpp
/* -------------------------------------------------------------------------- */
// TODO: this should be in Mesher.
// Removes triangles in the 2d mesh that have more than "max_keypoints_with_
// gradient" keypoints with higher gradient than "gradient_bound".
// Input the original triangulation: original_triangulation_2D
// Output the filtered triangulation wo high-gradient triangles:
// filtered_triangulation_2D.
// If gradient_bound < 0, the check is disabled.
this should be in Mesher.
Removes triangles in the 2d mesh that have more than "max_keypoints_with_
gradient" keypoints with higher gradient than "gradient_bound".
Input the original triangulation: original_triangulation_2D
Output the filtered triangulation wo high-gradient triangles:
filtered_triangulation_2D.
If gradient_bound < 0, the check is disabled.
this should be in Mesher . Removes triangles in the 2d mesh that have more than " max_keypoints_with_ gradient " keypoints with higher gradient than " gradient_bound " . Input the original triangulation : original_triangulation_2D Output the filtered triangulation wo high - gradient triangles : filtered_triangulation_2D . If gradient_bound < 0 the check is disabled .
void StereoFrame::filterTrianglesWithGradients(
    const std::vector<cv::Vec6f> &original_triangulation_2D,
    std::vector<cv::Vec6f> *filtered_triangulation_2D,
    const float &gradient_bound,
    const size_t &max_keypoints_with_gradient) const {
  CHECK_NOTNULL(filtered_triangulation_2D);
  CHECK_NE(filtered_triangulation_2D, &original_triangulation_2D)
      << "Input original_triangulation_2D should be different that the object "
      << "pointed by filtered_triangulation_2D. Input=*Output error.";
  if (gradient_bound == -1) {
    *filtered_triangulation_2D = original_triangulation_2D;
    LOG_FIRST_N(WARNING, 1) << "Filter triangles with gradients is disabled.";
    return;
  }
  cv::Mat img_grads;
  computeImgGradients(left_frame_.img_, &img_grads);
  for (const cv::Vec6f &triangle : original_triangulation_2D) {
    std::vector<std::pair<KeypointCV, double>> keypoints_with_high_gradient =
        UtilsOpenCV::FindHighIntensityInTriangle(img_grads, triangle,
                                                 gradient_bound);
    if (keypoints_with_high_gradient.size() <= max_keypoints_with_gradient) {
      filtered_triangulation_2D->push_back(triangle);
    }
  }
}
void StereoFrame :: filterTrianglesWithGradients ( const std :: vector < cv :: Vec6f > & original_triangulation_2D , std :: vector < cv :: Vec6f > * filtered_triangulation_2D , const float & gradient_bound , const size_t & max_keypoints_with_gradient ) const { CHECK_NOTNULL ( filtered_triangulation_2D ) ; CHECK_NE ( filtered_triangulation_2D , & original_triangulation_2D ) << " " << " " ; if ( gradient_bound == -1 ) { * filtered_triangulation_2D = original_triangulation_2D ; LOG_FIRST_N ( WARNING , 1 ) << " " ; return ; } cv :: Mat img_grads ; computeImgGradients ( left_frame_ . img_ , & img_grads ) ; for ( const cv :: Vec6f & triangle : original_triangulation_2D ) { std :: vector < std :: pair < KeypointCV , double > > keypoints_with_high_gradient = UtilsOpenCV :: FindHighIntensityInTriangle ( img_grads , triangle , gradient_bound ) ; if ( keypoints_with_high_gradient . size ( ) <= max_keypoints_with_gradient ) { filtered_triangulation_2D -> push_back ( triangle ) ; } } }
TODO: this should be in Mesher.
TODO : this should be in Mesher .
// Skip filter. // Compute img gradients. // For each triangle, set to full the triangles that have near-zero gradient. // triangulation2Dobs_.reserve(triangulation2D.size()); // TODO far too many loops over triangles. // Find all pixels with a gradient higher than gradBound. // If no high-grad pixels exist, // then this triangle is assumed to be a plane.