MATLAB--数字图像处理 特征点匹配
【摘要】 混乱场景目标图像检测(特征点匹配)
代码(从大佬那copy的)
boxImage = imread('car2_1.png');
sceneImage = imread('car2.jpg');
boxImage = rgb2gray(boxImage);
sceneImage =rgb2gray(sceneImage);
%% Step 2: 提取SURF特征...
混乱场景目标图像检测(特征点匹配)
代码(从大佬那copy的)
boxImage = imread('car2_1.png');
sceneImage = imread('car2.jpg');
boxImage = rgb2gray(boxImage);
sceneImage =rgb2gray(sceneImage);
%% 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');
结果图
文章来源: haihong.blog.csdn.net,作者:海轰Pro,版权归原作者所有,如需转载,请联系作者。
原文链接:haihong.blog.csdn.net/article/details/102628590
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)