0% found this document useful (0 votes)
119 views

Object Detection in A Cluttered Scene Using Point Feature Matching

The document loads two images, detects feature points, matches features between images, estimates a geometric transform, and overlays the transformed shapes onto the scene image to detect objects. It first detects features in a box image and scene image, matches features between the images, and estimates an affine transform. It then transforms the box polygon and overlays it on the scene image. Repeating this process, it detects an elephant in the scene by matching against a separate elephant image and transforming/overlaying the elephant polygon.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
119 views

Object Detection in A Cluttered Scene Using Point Feature Matching

The document loads two images, detects feature points, matches features between images, estimates a geometric transform, and overlays the transformed shapes onto the scene image to detect objects. It first detects features in a box image and scene image, matches features between the images, and estimates an affine transform. It then transforms the box polygon and overlays it on the scene image. Repeating this process, it detects an elephant in the scene by matching against a separate elephant image and transforming/overlaying the elephant polygon.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

boxImage = imread('stapleRemover.

jpg');
figure;
imshow(boxImage);
title('Image of a Box');

sceneImage = imread('clutteredDesk.jpg');
figure;
imshow(sceneImage);
title('Image of a Cluttered Scene');

boxPoints = detectSURFFeatures(boxImage);
scenePoints = detectSURFFeatures(sceneImage);

figure;
imshow(boxImage);
title('100 Strongest Feature Points from Box Image');
hold on;
plot(selectStrongest(boxPoints, 100));

figure;
imshow(sceneImage);
title('300 Strongest Feature Points from Scene Image');
hold on;
plot(selectStrongest(scenePoints, 300));

[boxFeatures, boxPoints] = extractFeatures(boxImage, boxPoints);


[sceneFeatures, scenePoints] = extractFeatures(sceneImage, scenePoints);

boxPairs = matchFeatures(boxFeatures, sceneFeatures);

matchedBoxPoints = boxPoints(boxPairs(:, 1), :);


matchedScenePoints = scenePoints(boxPairs(:, 2), :);
figure;
showMatchedFeatures(boxImage, sceneImage, matchedBoxPoints, ...
matchedScenePoints, 'montage');
title('Putatively Matched Points (Including Outliers)');

[tform, inlierBoxPoints, inlierScenePoints] = ...


estimateGeometricTransform(matchedBoxPoints, matchedScenePoints, 'affine');

figure;
showMatchedFeatures(boxImage, sceneImage, inlierBoxPoints, ...
inlierScenePoints, 'montage');
title('Matched Points (Inliers Only)')

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

newBoxPolygon = transformPointsForward(tform, boxPolygon);

figure;
imshow(sceneImage);
hold on;
line(newBoxPolygon(:, 1), newBoxPolygon(:, 2), 'Color', 'y');
title('Detected Box')
elephantImage = imread('elephant.jpg');
figure;
imshow(elephantImage);
title('Image of an Elephant');

elephantPoints = detectSURFFeatures(elephantImage);
figure;
imshow(elephantImage);
hold on;
plot(selectStrongest(elephantPoints, 100));
title('100 Strongest Feature Points from Elephant Image');

[elephantFeatures, elephantPoints] = extractFeatures(elephantImage,


elephantPoints);

elephantPairs = matchFeatures(elephantFeatures, sceneFeatures, 'MaxRatio', 0.9);

matchedElephantPoints = elephantPoints(elephantPairs(:, 1), :);


matchedScenePoints = scenePoints(elephantPairs(:, 2), :);
figure;
showMatchedFeatures(elephantImage, sceneImage, matchedElephantPoints, ...
matchedScenePoints, 'montage');
title('Putatively Matched Points (Including Outliers)');

[tform, inlierElephantPoints, inlierScenePoints] = ...


estimateGeometricTransform(matchedElephantPoints, matchedScenePoints,
'affine');
figure;
showMatchedFeatures(elephantImage, sceneImage, inlierElephantPoints, ...
inlierScenePoints, 'montage');
title('Matched Points (Inliers Only)');

elephantPolygon = [1, 1;... % top-left


size(elephantImage, 2), 1;... % top-right
size(elephantImage, 2), size(elephantImage, 1);... % bottom-right
1, size(elephantImage, 1);... % bottom-left
1,1]; % top-left again to close the polygon

newElephantPolygon = transformPointsForward(tform, elephantPolygon);

figure;
imshow(sceneImage);
hold on;
line(newBoxPolygon(:, 1), newBoxPolygon(:, 2), 'Color', 'y');
line(newElephantPolygon(:, 1), newElephantPolygon(:, 2), 'Color', 'g');
title('Detected Elephant and Box');

You might also like