物体检测SURF算法matlab实现

来源:互联网 发布:运用python成为黑客 编辑:程序博客网 时间:2024/05/29 07:19

注:此次实现中用到的函数需要在matlab2013后的版本才能正常运行,故顺手附上matlab2014b下载地址: http://download.csdn.net/detail/lrrent/9499859

close all;clear all;clc;boxImage = imread('2_2.jpg');sceneImage = imread('2.jpeg');sceneImage = rgb2gray(sceneImage);boxImage = rgb2gray(boxImage);boxPoints = detectSURFFeatures(boxImage);scenePoints = detectSURFFeatures(sceneImage);[boxFeatures,boxPoints] = extractFeatures(boxImage,boxPoints);[sceneFeatures,scenePoints] = extractFeatures(sceneImage,scenePoints);boxPairs = matchFeatures(boxFeatures,sceneFeatures);% display putatively matched featuresmatchedBoxPoints = boxPoints(boxPairs(:,1),:);matchedScenePoints = scenePoints(boxPairs(:,2),:);figure;showMatchedFeatures(boxImage,sceneImage,matchedBoxPoints,matchedScenePoints,'montage'):title('Matched Points(Including Outliers)');[tform,inlierBoxPoints,inlierScenePoints] = estimateGeometricTransform(matchedBoxPoints,matchedScenePoints,'affine');% display the matching points pairs with the outliers removedfigure;showMatchedFeatures(boxImage,sceneImage,inlierBoxPoints,inlierScenePoints,'montage'):title('Matched Points(inliers Only)');% Get the bounding polygon of the reference imageboxPolygon = [1,1;              size(boxImage,2),1;              size(boxImage,2),size(boxImage,1);              1,size(boxImage,1);              1,1];newBoxPolygon = transformPointsForward(tform,boxPolygon);% displayfigure;imshow(sceneImage);hold on;line(newBoxPolygon(:,1),newBoxPolygon(:,2),'Color','y');title('Detected Box');figure; imshow(boxImage);title('100 Strongest Feature Points from Box Image');hold on;plot(boxPoints.selectStrongest(100));figure; imshow(sceneImage);title('300 Strongest Feature Points from Scene Image');hold on;plot(scenePoints.selectStrongest(300));
0 0
原创粉丝点击