特征提取结果
特征匹配结果
#include "openMVG/features/feature.hpp"
#include "openMVG/features/sift/SIFT_Anatomy_Image_Describer.hpp"
#include "openMVG/features/svg_features.hpp"
#include "openMVG/image/image_io.hpp"
#include "openMVG/image/image_concat.hpp"
#include "openMVG/matching/regions_matcher.hpp"
#include "openMVG/matching/svg_matches.hpp"
//
#include "third_party/stlplus3/filesystemSimplified/file_system.hpp"
#include <cstdlib>
#include <string>
#include <iostream>
using namespace openMVG;
using namespace openMVG::image;
using namespace openMVG::matching;
using namespace std;
int main() {
Image<RGBColor> image;
//左右视图文件路径
string jpg_filenameL = stlplus::folder_up(string(THIS_SOURCE_DIR))+ "/imageData/StanfordMobileVisualSearch/Ace_0.png";
string jpg_filenameR = stlplus::folder_up(string(THIS_SOURCE_DIR))+ "/imageData/StanfordMobileVisualSearch/Ace_1.png";
//左右视图文件读取
Image<unsigned char> imageL, imageR;
ReadImage(jpg_filenameL.c_str(), &imageL);
ReadImage(jpg_filenameR.c_str(), &imageR);
//调用openMVG特征提取接口提取SIFI特征,存储在features::Regions中,(position, ...) + attributes
using namespace openMVG::features;
std::unique_ptr<Image_describer> image_describer(new SIFT_Anatomy_Image_describer);
std::map<IndexT, std::unique_ptr<features::Regions>> regions_perImage;
image_describer->Describe(imageL, regions_perImage[0]);
image_describer->Describe(imageR, regions_perImage[1]);
//获取特征点位置
const PointFeatures
featsL = regions_perImage.at(0)->GetRegionsPositions(),
featsR = regions_perImage.at(1)->GetRegionsPositions();
//垂直拼接左右影像,并保存
{
Image<unsigned char> concat;
ConcatV(imageL, imageR, concat);
string out_filename = "00_images.jpg";
WriteImage(out_filename.c_str(), concat);
}
//动态类型转换为SIFT_Regions,Regions是一个抽象类
const SIFT_Regions* regionsL = dynamic_cast<SIFT_Regions*>(regions_perImage.at(0).get());
const SIFT_Regions* regionsR = dynamic_cast<SIFT_Regions*>(regions_perImage.at(1).get());
//绘制图像特征
{
Features2SVG
(
jpg_filenameL,
{imageL.Width(), imageL.Height()},
regionsL->Features(),
jpg_filenameR,
{imageR.Width(), imageR.Height()},
regionsR->Features(),
"01_features.svg"
);
}
//执行特征匹配,采用暴力匹配算法基于L2距离,并保留80%的结果
std::vector<IndMatch> vec_PutativeMatches;
{
// Find corresponding points
matching::DistanceRatioMatch(
0.8, matching::BRUTE_FORCE_L2,
*regions_perImage.at(0).get(),
*regions_perImage.at(1).get(),
vec_PutativeMatches);
//绘制特征匹配结果
const bool bVertical = true;
Matches2SVG
(
jpg_filenameL,
{imageL.Width(), imageL.Height()},
regionsL->GetRegionsPositions(),
jpg_filenameR,
{imageR.Width(), imageR.Height()},
regionsR->GetRegionsPositions(),
vec_PutativeMatches,
"02_Matches.svg",
bVertical
);
}
//输出左右特征数量,以及特征匹配结果![请添加图片描述](https://img-blog.csdnimg.cn/direct/d9b9749b35554210aec4c6ed8870a3a1.jpeg)
std::cout << featsL.size() << " Features on image A" << std::endl
<< featsR.size() << " Features on image B" << std::endl
<< vec_PutativeMatches.size() << " matches after matching with Distance Ratio filter" << std::endl;
return EXIT_SUCCESS;
}