我有一个使用Harris角落检测器绘制的特征点保存的图像(.fig),然后我想在第二张图像上映射特征点,然后将它们与保存的图像进行比较显示匹配的功能点。我想为如何解决这个帮助。
映射"模板"图像的代码:
I1 = rgb2gray(imread('/home/colin/downloads/matlabImages/template.jpg'));
points1 = detectHarrisFeatures(I1);
imshow(I1); hold on;
plot(points1);
绘制时刚刚使用"文件 -> saveas"选项保存了此图像。
然后,我正在尝试运行一个单独的脚本来绘制新图像上的功能并比较它们,这是我遇到问题的地方。
比较脚本:
I1 = hgload('/home/colin/tmp/untitled.fig');
I2 = rgb2gray(imread('/home/colin/downloads/matlabImages/small.jpg'));
points2 = detectHarrisFeatures(I2);
[features2, valid_points2] = extractFeatures(I2, points2);
indexPairs = matchFeatures(I1, features2);
matched_points2 = valid_points2(indexPairs(:, 2), :);
figure; showMatchedFeatures(I1, I2, matched_points2);
您可以想象我会遇到一系列错误:
Error using coder.internal.errorIf (line 9)
Expected FEATURES1 and FEATURES2 to be the same class.
Error in matchFeatures>assignFeaturesAndMetric (line 356)
coder.internal.errorIf(~isequal(class(f1), class(f2)),...
Error in matchFeatures>parseInputs (line 343)
[features1, features2, metric] = assignFeaturesAndMetric(f1, f2, metric);
Error in matchFeatures (line 196)
[features1, features2, metric, match_thresh, method, maxRatioThreshold, ...
Error in comparePoints (line 6)
indexPairs = matchFeatures(I1, features2);
您没有保存正确的信息。保存 .fig 时,您只保存图。
您需要保存I1
和points1
:
I1 = rgb2gray(imread('/home/colin/downloads/matlabImages/template.jpg'));
points1 = detectHarrisFeatures(I1);
save('im1.mat', 'I1','points1');
现在您可以使用信息:
load('im1.mat');%This loads I1 and points1
I2 = rgb2gray(imread('/home/colin/downloads/matlabImages/small.jpg'));
points2 = detectHarrisFeatures(I2);
[features2, valid_points2] = extractFeatures(I2, points2);
[features1, valid_points1] = extractFeatures(I1, points1);
indexPairs = matchFeatures(features1, features2);
> Optional ,您可以在第一步中计算features1
变量并保存(而不是使用I1
和points1
):
I1 = rgb2gray(imread('/home/colin/downloads/matlabImages/template.jpg'));
points1 = detectHarrisFeatures(I1);
[features1, valid_points1] = extractFeatures(I1, points1);
save('im1.mat', 'features1');
load('im1.mat');%This loads features1
I2 = rgb2gray(imread('/home/colin/downloads/matlabImages/small.jpg'));
points2 = detectHarrisFeatures(I2);
[features2, valid_points2] = extractFeatures(I2, points2);
indexPairs = matchFeatures(features1, features2);