首页
登录 | 注册

基于特征点的物体检测

本教程是一种用于基于在参考图像和目标图像之间找到点对应关系来检测特定对象的算法。尽管尺度变化或平面内旋转,它仍可以检测物体。它对于少量的平面外旋转和遮挡也很稳健。

这种对象检测方法最适用于呈现非重复纹理图案的对象,这会产生独特的特征匹配。对于均匀着色的对象或包含重复图案的对象,此技术不太适用。请注意,此算法用于检测特定对象,例如参考图像中的大象,而不是任何大象。

使用的图片
基于特征点的物体检测

基于特征点的物体检测


完整的Matlab代码

%% 清楚工作空间
clc;
clear all;

%% 读取参考图片 
boxImage = imread('stapleRemover.jpg');
boxImage = rgb2gray(boxImage);
figure;
imshow(boxImage);
title('Image of a Box');

%% 读取要处理的图片
sceneImage = imread('clutteredDesk.jpg');
sceneImage = rgb2gray(sceneImage);
figure;
imshow(sceneImage);
title('Image of a Cluttered Scene');

%% 提取特征点
boxPoints = detectSURFFeatures(boxImage);
scenePoints = detectSURFFeatures(sceneImage);

%% Visualize the strongest feature points found in the reference image.
figure;
imshow(boxImage);
title('100 Strongest Feature Points from Box Image');
hold on;
plot(selectStrongest(boxPoints, 100));

%% Visualize the strongest feature points found in the target image.
figure;
imshow(sceneImage);
title('300 Strongest Feature Points from Scene Image');
hold on;
plot(selectStrongest(scenePoints, 300));

%% 提取特征描述
[boxFeatures, boxPoints] = extractFeatures(boxImage, boxPoints);
[sceneFeatures, scenePoints] = extractFeatures(sceneImage, scenePoints);

%% 找到匹配点
boxPairs = matchFeatures(boxFeatures, sceneFeatures);

%% 显示匹配效果
matchedBoxPoints = boxPoints(boxPairs(:, 1), :);
matchedScenePoints = scenePoints(boxPairs(:, 2), :);
figure;
showMatchedFeatures(boxImage, sceneImage, matchedBoxPoints, ...
    matchedScenePoints, 'montage');
title('Putatively Matched Points (Including Outliers)');

%% 通过匹配找到特定的物体
[tform, inlierBoxPoints, inlierScenePoints] = ...
    estimateGeometricTransform(matchedBoxPoints, matchedScenePoints, 'affine');
%% 显示匹配效果
figure;
showMatchedFeatures(boxImage, sceneImage, inlierBoxPoints, ...
    inlierScenePoints, 'montage');
title('Matched Points (Inliers Only)');

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
newBoxPolygon = transformPointsForward(tform, boxPolygon);

%% 显示被检测到的物体
figure;
imshow(sceneImage);
hold on;
line(newBoxPolygon(:, 1), newBoxPolygon(:, 2), 'Color', 'y');
title('Detected Box');






2020 jeepxie.net webmaster#jeepxie.net
10 q. 0.008 s.
京ICP备10005923号