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;
}