主要内容

在一个杂乱的场景中使用点特征匹配的目标检测

这个例子展示了如何在一个杂乱的场景中检测一个特定的物体,给定一个物体的参考图像。

概述

该示例呈现了一种基于参考和目标图像之间的查找点对应的特定对象来检测特定对象的算法。尽管缩小变化或面内旋转,它可以检测对象。它对少量外平面旋转和闭塞也是强大的。

这种对象检测方法最适合展示非重复纹理模式的对象,这导致独特的特征匹配。这种技术不太可能适用于均匀彩色的物体,或用于包含重复模式的物体。注意,该算法被设计用于检测特定对象,例如参考图像中的大象,而不是任何大象。用于检测特定类别的对象,例如人或面部,参见Vision.peopledetectorVision.cascadeObjectDetector

第一步:阅读图像

读取包含感兴趣对象的参考图像。

boximage = imread('stapleremover.jpg');图;imshow(盒子);标题(“盒子的图像”);

读取包含混乱场景的目标图像。

sceneimage = imread('cluttereddesk.jpg');图;imshow (sceneImage);标题(“杂乱场景的图像”);

第2步:检测特征点

检测两幅图像的特征点。

boxpoints = detectsurfeatures(bondimage);情景=检测到(SceeImage);

将参考图像中最强的特征点可视化。

图;imshow(盒子);标题('来自Box Image的100个最强大的功能点');抓住;情节(selectStrongest (boxPoints, 100));

可视化目标图像中找到的最强特征点。

图;imshow (sceneImage);标题(从场景图像中的300个最强的特征点');抓住;绘图(Selectstrongest(Selectstrongest(SynePoints,300));

步骤3:提取特征描述符

提取两幅图像感兴趣点的特征描述符。

[BoxFeatures,Boxpoints] = ExtractFeatures(BoxImage,Boxpoints);[scenefeatures,scenepoints] =提取物(sceneImage,synepoints);

第4步:找到推定点匹配

使用特性描述符匹配特性。

boxPairs = matchFeatures(boxFeatures, sceneFeatures);

显示带匹配的功能。

matchedBoxPoints = boxPoints(boxPairs(:, 1),:);matchedScenePoints = scenePoints(boxPairs(:, 2),:);图;showMatchedFeatures (boxImage sceneImage matchedBoxPoints,......matchedscenepoints,'剪辑');标题(假定匹配点(包括离群点));

第五步:使用假定匹配定位场景中的对象

estimateGeometricTransform2D计算与匹配点相关的转换,同时消除异常值。此转换允许我们本地化场景中的对象。

[tform,inlieridx] =......eStisimeGeometricTransform2D(MatchedBoxPoints,matchedScenepoints,'仿射');inlierBoxPoints = matchedBoxPoints(inlierIdx,:);inlierScenePoints = matchedScenePoints(inlierIdx,:);

显示匹配点对具有删除的异常值

图;ShowMatchedFeatures(BOXIMAGE,SUSHIMIMAGE,INLIELBOXPOINTS,......inlierscenepoints,'剪辑');标题('匹配点(仅限最基于)');

得到参考图像的边界多边形。

boxpolygon = [1,1;......%左上的尺寸(boxImage, 2), 1;......% 右上size(boxImage, 2), size(boxImage, 1);......%右下方1,尺寸(BOXIMAGE,1);......% 左下方1,1];%重新左侧再次关闭多边形

将多边形转换为目标图像的坐标系统。变换后的多边形表示物体在场景中的位置。

newboxpolygon = transformpointsforword(tform,boxpolygon);

显示检测到的对象。

图;imshow (sceneImage);抓住;newBoxPolygon(:, 1), newBoxPolygon(:, 2),“颜色”'是');标题('检测到的盒子');

第7步:检测另一个对象

使用与前面相同的步骤检测第二个对象。

读取包含第一个感兴趣对象的图像。

elephantImage = imread (“elephant.jpg”);图;imshow(elephantimage);标题('大象的形象');

检测和可视化特征点。

Elephantpoints =检测(ElephantImage);图;imshow(elephantimage);抓住;情节(selectStrongest (elephantPoints, 100));标题(“大象图像中最强的100个特征点”);

提取特征描述符。

[Elephantfeatures,Elephantpoints] =提取物(Elephantimage,Elephantpoints);

匹配功能

Elephantpairs = MatchFeatures(象形物质,风景,'maxratio', 0.9);

显示带匹配的功能。

matchedElephantPoints = elephantPoints(elephantPairs(:, 1),:);matchedScenePoints = scenePoints(elephantPairs(:, 2),:);图;showMatchedFeatures (elephantImage sceneImage matchedElephantPoints,......matchedscenepoints,'剪辑');标题(假定匹配点(包括离群点));

估计几何变换并消除异常值

[tform,Inlierelephantpoints,Inlierscenepoints] =......estimateGeometricTransform (matchedElephantPoints matchedScenePoints,'仿射');图;showMatchedFeatures (elephantImage sceneImage inlierElephantPoints,......inlierscenepoints,'剪辑');标题('匹配点(仅限最基于)');

显示两个对象

elephantPolygon = [1,1;......%左上的尺寸(elephantimage,2),1;......% 右上尺寸(elephantimage,2),尺寸(elephantimage,1);......%右下方1、大小(elephantImage, 1);......% 左下方1,1];%重新左侧再次关闭多边形Newelephantpolygon = Transformpointsforward(Tform,ElephantPolygon);图;imshow (sceneImage);抓住;newBoxPolygon(:, 1), newBoxPolygon(:, 2),“颜色”'是');线(Newelephantpolygon(:, 1),Newelephantpolygon(:,2),“颜色”'G');标题(“发现大象与箱子”);