您的位置:首页 > 理论基础

计算机视觉 | 使用MATLAB实现图像SURF特征的提取与匹配以及目标定位(代码类)

2018-12-12 19:49 716 查看
版权声明:本文为博主原创文章,未经博主允许不得转载。转载注明文章出处!!! https://blog.csdn.net/u011344545/article/details/84978195

了解博主更多项目查看

github:https://github.com/MichaelBeechan

CSDN:https://blog.csdn.net/u011344545

====================================================================

%% Name:Michael Beechan
%% School:Chongqing University of Technology
%% Time:2018.12.11
%% FunctionExtract image features

原图像:

%% read image
boxImage = imread('1.jpg');
boxImage = rgb2gray(boxImage);
%{
figure;
imshow(boxImage);
title('Image of a box');
%}
sceneImage = imread('2.jpg');
sceneImage = rgb2gray(sceneImage);
%{
figure;
imshow(sceneImage);
title('Image of cluttered scene');
%}

%% detect image feature points
boxPoints = detectSURFFeatures(boxImage);
scenePoints = detectSURFFeatures(sceneImage);
figure(1);
imshow(boxImage);
title('100 Feature Points');
hold on;
plot(selectStrongest(boxPoints, 100));
 

figure(2);
imshow(sceneImage);
title('300 Feature Points');
hold on;
plot(selectStrongest(scenePoints, 300));

%% Extract feature descriptor
[boxFeatures, boxPoints] = extractFeatures(boxImage, boxPoints);
[sceneFeatures, scenePoints] = extractFeatures(sceneImage, scenePoints);

%% find Putative point matches
boxPairs = matchFeatures(boxFeatures, sceneFeatures);

%% display matched features
matchedBoxPoints = boxPoints(boxPairs(:, 1), :);
matchedScenePoints = scenePoints(boxPairs(:, 2), :);
figure(3);
showMatchedFeatures(boxImage, sceneImage, matchedBoxPoints, matchedScenePoints, 'montage');
title('Putatively Matched Points(Including Outliers)');

%% Locate the Object in Scene Using Putative Matches
[tform, inlierBoxPoints, inlierScenePoints] = ...
    estimateGeometricTransform(matchedBoxPoints, matchedScenePoints, 'affine');
figure(4);
showMatchedFeatures(boxImage, sceneImage, inlierBoxPoints, inlierScenePoints, 'montage');
title('Matched Points(Inliers Only)');
 

%% Get the bounding polygon(多边形)of the reference image
boxPolygon = [1, 1;...                              %top-left
        size(boxImage, 2), 1;...                    %top-right
        size(boxImage, 2), size(boxImage, 1);...    %bottom-right
        1, size(boxImage, 1);...                    %bottom-left
        1, 1];                                      %top-left again to close the polygon
%% Transform the polygon into the coordinate system of the target image
%% The transformed polygon indicates the location of the object in scene

newBoxPolygon = transformPointsForward(tform, boxPolygon);
figure(5);
imshow(sceneImage);
hold on;
line(newBoxPolygon(:, 1), newBoxPolygon(:, 2), 'Color', 'y');
title('Detected Box');

 

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