案例2:OpenMVG的GMS特征匹配过滤

在这里插入图片描述GMS过滤前后对比

#include "openMVG/image/image_io.hpp"
#include "openMVG/image/image_concat.hpp"
#include "openMVG/features/akaze/image_describer_akaze.hpp"
#include "openMVG/features/sift/SIFT_Anatomy_Image_Describer.hpp"
#include "openMVG/features/svg_features.hpp"
#include "openMVG/matching/regions_matcher.hpp"
#include "openMVG/matching/svg_matches.hpp"
#include "openMVG/robust_estimation/gms_filter.hpp"

#include "third_party/cmdLine/cmdLine.h"
#include "third_party/stlplus3/filesystemSimplified/file_system.hpp"

#include <memory>
#include <string>

using namespace openMVG;
using namespace openMVG::image;
using namespace openMVG::robust;
using namespace std;

int main(int argc, char **argv) {
  //https://blog.csdn.net/m0_48465302/article/details/138077587?spm=1001.2014.3001.5501
  //特征匹配参考之前的文章
  //GMS过滤匹配
  {
    //左右图像特征点格式转换
    std::vector<Eigen::Vector2f> vec_points_left;
    {
      const auto & regions_pos = regions_perImage.at(0)->GetRegionsPositions();
      vec_points_left.reserve(regions_pos.size());
      for (const auto & it : regions_pos)
        vec_points_left.push_back({it.x(), it.y()});
    }
    std::vector<Eigen::Vector2f> vec_points_right;
    {
      const auto & regions_pos = regions_perImage.at(1)->GetRegionsPositions();
      vec_points_right.reserve(regions_pos.size());
      for (const auto & it : regions_pos)
        vec_points_right.push_back({it.x(), it.y()});
    }
		//GMS初始化
    const int kGmsThreshold = 6;
    robust::GMSFilter gms(
      vec_points_left,  {imageL.Width(), imageL.Height()},
      vec_points_right, {imageR.Width(), imageR.Height()},
      vec_PutativeMatches,
      kGmsThreshold);
    const bool with_scale_invariance = true;
    const bool with_rotation_invariance = true;
    std::vector<bool> inlier_flags;
    //GMS执行,返回值为过滤之后的匹配数量
    const int nb_inliers = gms.GetInlierMask(inlier_flags,
                                             with_scale_invariance,
                                             with_rotation_invariance);
    std::cout
      << vec_points_left.size() << " #Features on image A" << std::endl
      << vec_points_right.size() << " #Features on image B" << std::endl
      << nb_inliers << " #matches kept by the GMS Filter" << std::endl;
		//获取过滤之后的匹配
    matching::IndMatches vec_gms_matches;
    for (int i = 0; i < static_cast<int>(inlier_flags.size()); ++i)
    {
      if (inlier_flags[i])
        vec_gms_matches.push_back(vec_PutativeMatches[i]);
    }
    // 可视化过滤之后的匹配
    {
      const bool bVertical = true;
      Matches2SVG
      (
        jpg_filenameL,
        {imageL.Width(), imageL.Height()},
        regions_perImage.at(0)->GetRegionsPositions(),
        jpg_filenameR,
        {imageR.Width(), imageR.Height()},
        regions_perImage.at(1)->GetRegionsPositions(),
        vec_gms_matches,
        "03_GMSMatches.svg",
        bVertical
      );
    }
  }
  return EXIT_SUCCESS;
}

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值