MATLAB——混乱场景目标图像检测(特征点匹配)

%本例描绘在一个混乱场景检测一个盒子,目标物匹配策略为寻找SURF特征匹配
%并根据特征点仿射变化去除野值

%% Step 1: 读取图片
boxImage = imread('stapleRemover.jpg');
sceneImage = imread('clutteredDesk.jpg');

%% Step 2: 提取SURF特征点
boxPoints = detectSURFFeatures(boxImage);
scenePoints = detectSURFFeatures(sceneImage);

%% Step 3: 根据特征点生成图像的特征向量
[boxFeatures, boxPoints] = extractFeatures(boxImage, boxPoints);
[sceneFeatures, scenePoints] = extractFeatures(sceneImage, scenePoints);

%% Step 4: 初步建立一个匹配对(含野值)
boxPairs = matchFeatures(boxFeatures, sceneFeatures);
%show
matchedBoxPoints = boxPoints(boxPairs(:, 1), :);
matchedScenePoints = scenePoints(boxPairs(:, 2), :);
figure(1);
showMatchedFeatures(boxImage, sceneImage, matchedBoxPoints,matchedScenePoints, 'montage');
title('Putatively Matched Points (Including Outliers)');

%% Step 5: 预测仿射变化,去除不满足变化的野值
[tform, inlierBoxPoints, inlierScenePoints] = estimateGeometricTransform(matchedBoxPoints, matchedScenePoints, 'affine');
figure(2);
showMatchedFeatures(boxImage, sceneImage, inlierBoxPoints,inlierScenePoints, 'montage');
title('Matched Points (Inliers Only)');

%% Step 6:获取目标物的多边形框

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

%Display the detected object.
figure(3);
imshow(sceneImage);hold on;line(newBoxPolygon(:, 1), newBoxPolygon(:, 2), 'Color', 'y');
title('Detected Box');

含野值的特征点匹配:

去野值的特征点匹配:

标记目标物的多边形框;

 

  • 14
    点赞
  • 97
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 8
    评论
MATLAB中,可以使用Harris角点检测算法来进行特征匹配。Harris角点检测算法是一种经典的角点检测算法,它通过计算图像中每个像素点的角点响应函数来识别角点。 下面是一个使用Harris角点检测的特征匹配的示例代码: ```matlab % 读取两幅图像 image1 = imread('image1.jpg'); image2 = imread('image2.jpg'); % 转换为灰度图像 grayImage1 = rgb2gray(image1); grayImage2 = rgb2gray(image2); % 使用Harris角点检测算法检测角点 cornerPoints1 = detectHarrisFeatures(grayImage1); cornerPoints2 = detectHarrisFeatures(grayImage2); % 提取角点特征描述符 features1 = extractFeatures(grayImage1, cornerPoints1); features2 = extractFeatures(grayImage2, cornerPoints2); % 进行特征匹配 indexPairs = matchFeatures(features1, features2); % 选取匹配点对 matchedPoints1 = cornerPoints1(indexPairs(:, 1)); matchedPoints2 = cornerPoints2(indexPairs(:, 2)); % 可视化匹配结果 figure; showMatchedFeatures(image1, image2, matchedPoints1, matchedPoints2, 'montage'); ``` 注意,在使用该代码之前,需要将`image1.jpg`和`image2.jpg`替换为实际的图像文件路径。 这段代码中,首先将两幅图像转换为灰度图像,然后利用`detectHarrisFeatures`函数检测图像中的角点,接着使用`extractFeatures`函数提取角点的特征描述符,最后使用`matchFeatures`函数进行特征匹配,并利用`showMatchedFeatures`函数可视化匹配结果。 希望对你有所帮助!如果有任何问题,请随时追问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Ephemeroptera

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值