您的位置:首页 > Web前端

mexopencv-利用orb feature detector 提取和匹配特征

2012-08-10 21:43 1066 查看
1.安装配置好环境后,由于时间急需,第一次利用mexopecv进行测试,提取图片的ORB特征点,并进行匹配试验。

2.匹配的程序编写调式过程中,有几个问题:

参数的理解,各个函数模块的组合(参考opencv 的实现例子)

3.代码

%orb feature detector test
%vl_sift matlab 自我测试数据对比
function ouput = test_orb(flag)
addpath('D:\\work\\SLAM\\MonoSLAMMatlab\\tools\\mexopencv\\');
% import cv.*;
imageFile1 = '1.pgm';
imageFile2 = '2.pgm';
% Load image
image1 = imread(imageFile1);
image2 = imread(imageFile2);
if ndims(image1) == 3
image1 = rgb2gray(image1);
end
if ndims(image2) == 3
image2 = rgb2gray(image2);
end

% I = rgb2gray(image1); % Conversion to single is recommended
% J = rgb2gray(image2); % in the documentation

rand('state',0);
% uv=rand(2,1);
if flag ~= 1
A = image1(20:200,20:200);
B = image2(20:200,20:200);
else
A = image1;
B = image2;
end

[K1 D1] = cv.ORB(A,'NFeatures',500);
[K2 D2] = cv.ORB(B,'NFeatures',500);

% Where 1.5 = ratio between euclidean distance of NN2/NN1
im1 = cv.drawKeypoints(A,K1);
subplot(2,1,1);
hold on;
imshow(im1);

im2 = cv.drawKeypoints(B,K2);
subplot(2,1,2);
imshow(im2);
hold off;
%定义匹配的类对象
matcher = cv.DescriptorMatcher('BruteForce-Hamming');
matcher.add(D1);
matcher.train();
matcher_img = matcher.match(D2);
im3 = cv.drawMatches(A,K1,B,K2,matcher_img);
figure;
imshow(im3);
%     [matches score] = vl_ubcmatch(D1,D2,1.5);
%    figure01=figure;
%     h1=subplot(1,2,1);
%     imshow(uint8(A));
%     hold on;
%展示匹配点

%     plot(F1(1,matches(1,:)),F1(2,matches(1,:)),'b*');
%
%     h2=subplot(1,2,2);
%     imshow(uint8(B));
%     hold on;
%
%     plot(F2(1,matches(2,:)),F2(2,matches(2,:)),'r*');
%

end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: