文章出處

轉戰matlab了。步驟說一下:
目標圖obj 含目標的場景圖scene

  1. 載入圖像
  2. 分別檢測SURF特征點
  3. 分別提取SURF描述子,即特征向量
  4. 用兩個特征相互匹配
  5. 利用匹配結果計算兩者之間的transform關系tform
  6. 根據obj位置與變換關系tform,在scene圖上框出obj

代碼,來自matlab,http://localhost:9090/vision/gs/object-detection-and-tracking.html#btt5qyu

%step1:讀取圖片
%讀取object圖片
boxImage = imread('stapleRemover.jpg');
%讀取場景圖片
sceneImage = imread('clutteredDesk.jpg');

%step2:檢測特征點
boxPoints = detectSURFFeatures(boxImage);
scenePoints = detectSURFFeatures(sceneImage);

% figure; imshow(boxImage);
% title('Box Image中最強的100個feature points');
% hold on;
% plot(boxPoints.selectStrongest(100));

%step3 extract feature descriptors  提取出特征的描述子
%使用extractFeatures(),具體的feature類型是通過boxPoints位置的參數指定的,這里是SURF
%爛設計,為什么extractFeatures輸入了boxPoints后,還要返回boxPoints?
[boxFeatures, boxPoints] = extractFeatures(boxImage, boxPoints);
[sceneFeatures, scenePoints] = extractFeatures(sceneImage, scenePoints);

%step4 find putative point matches
%Match the features using their descriptors.
boxPairs = matchFeatures(boxFeatures, sceneFeatures);
%Display putatively matched features.
matchedBoxPoints = boxPoints(boxPairs(:,1), :);
matchedScenePoints = scenePoints(boxPairs(:,2),:);
figure;
showMatchedFeatures(boxImage, sceneImage, matchedBoxPoints, matchedScenePoints, 'montage');
title('Putatively Matched Points (Including Outliers)');

%step5 locate the Object in the Scene Using Putative Matches
[tform, inlierBoxPoints, inlierScenePoints] = ...
    estimateGeometricTransform(matchedBoxPoints, matchedScenePoints, 'affine');
figure;
showMatchedFeatures(boxImage, sceneImage, inlierBoxPoints, ...
    inlierScenePoints, 'montage');
title('Matched Points (Inliers Only)');

%Get the bounding polygon of the reference image.
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
%將多邊形變換到目標圖片上,變換的結果表示了物體的位置
newBoxPolygon = transformPointsForward(tform, boxPolygon);

%display the detected object 顯示被檢測到的物體
figure; imshow(sceneImage);
hold on;
line(newBoxPolygon(:, 1), newBoxPolygon(:, 2), 'Color', 'y');
title('Detected Box');

文章列表


不含病毒。www.avast.com
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()