Harris角点检测+sift描述匹配

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wangyang20170901/article/details/82455646

    最近用到:Harris检测图像中边缘处的特征点,并且需要两张图特征点匹配起来。Harris只是一个角点检测的算法,最终只得到特征点坐标,想要匹配需要描述,而Harris是单尺度的,自己写描述函数又有些麻烦。找到MATLAB和opencv都有集成的函数:

MATLAB版本通过调节参数,效果还可以,存在一定的误匹配。

clc,clear
%读取、灰度化、显示
I1= imread('sample_01.jpg');  
I1=rgb2gray(I1);  %把RGB图像变成灰度图像
% figure
% imshow(I1)

I2= imread('sample_10.jpg');   
I2=rgb2gray(I2);
% figure
% imshow(I2)

%寻找特征点  
points1 = detectHarrisFeatures(I1,'MinQuality',0.002);  %读取特征点,'MinQuality',0.005
% points2 = detectSURFFeatures(I2);   
points2 = detectHarrisFeatures(I2,'MinQuality',0.002); 

figure
imshow(I1);
hold on;
plot(points1);

figure
imshow(I2);
hold on;
plot(points2);

%Extract the features.计算描述向量  
[f1, vpts1] = extractFeatures(I1, points1);  
[f2, vpts2] = extractFeatures(I2, points2);  

%进行匹配  
indexPairs = matchFeatures(f1, f2,'Method','NearestNeighborSymmetric','MatchThreshold',20) ;  
%用'Method','NearestNeighborSymmetric',阈值调节用'MatchThreshold',范围0-100,表示选择最强的匹配的百分比,越大匹配点越多
%用'Method','NearestNeighborRatio',阈值调节'MaxRatio',0.7,范围0-1,默认0.6,较大该值获得较多匹配
matched_pts1 = vpts1(indexPairs(:, 1));
matched_pts2 = vpts2(indexPairs(:, 2));

resultpairs1 = matched_pts1.Location; %存储匹配点坐标
resultpairs2 = matched_pts2.Location;

%显示匹配
figure('name','匹配后的图像'); 
showMatchedFeatures(I1,I2,matched_pts1,matched_pts2,'montage');  
legend('matched points 1','matched points 2'); 

OPENCV版本误匹配实在太多,没找到具体原因,选择的匹配方法是BruteForce。优点是opencv内部有Harris的改进版本goodFeaturesToTrack,可以进行Shi-Tomasi角点检测,能够设置角点数目,角点之间的最小距离,避免Harris点过于密集重复。

猜你喜欢

转载自blog.csdn.net/wangyang20170901/article/details/82455646