最近用到: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,表示选择最强的匹配的百分比,