您的位置:首页 > 运维架构

使用RANSAC提纯ORB和BRISK特征点,达到鲁棒匹配的效果(OpenCV 2.4.13下,源码)

2016-12-25 16:44 876 查看
#include
#include
#include
#include
#include

using namespace std;
using namespace cv;
int main() {

//Read images
Mat graf_1, graf_3;
graf_1 = imread("../data/vggAffineDataset/graf/img1.ppm");
graf_3 = imread("../data/vggAffineDataset/graf/img3.ppm");
if (graf_1.empty() || graf_3.empty()){
cerr<<"No images"< kp1, kp3;
orb.detect(graf_1,kp1);
orb.detect(graf_3,kp3);
//brisk.detect(graf_1,kp1);
//brisk.detect(graf_3,kp3);
cout<<"The number of keypoints of graf_1 is "< matches;
matcher.match(desc_1,desc_3,matches);
double max_dist = 0;
double min_dist = 10000;
for (int i = 0; i < matches.size(); ++i) {
if (matches[i].distance < min_dist)
min_dist = matches[i].distance;
if (matches[i].distance > max_dist)
max_dist = matches[i].distance;
}

vector goodMatches;
for (int j = 0; j < matches.size(); ++j) {
if (matches[j].distance < 4*min_dist)
goodMatches.push_back(matches[j]);
}
cout<<"Matches is "<(k,0) = pt1.x;
p1.at(k,1) = pt1.y;

pt3 = kp3[goodMatches[k].trainIdx].pt;
p3.at(k,0) = pt3.x;
p3.at(k,1) = pt3.y;
}

vector m_RANSACStatus;
findHomography(p1,p3,CV_RANSAC,3,m_RANSACStatus);

int inlinerCount = 0;
for (int l = 0; l < ptCount; ++l) {
if (m_RANSACStatus[l] != 0)
inlinerCount++;
}
cout<<"inlinerCount is "< inlierMatches;
for (int i=0; i

实验效果图:



(kp_graf_1)



(kp_graf_3)



(不经过任何处理的图像匹配)



(使用距离小于最小距离10倍时的匹配效果)



(使用RANSAC算法提纯后的图像匹配效果)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息