how to detect only specific object

i used feature extracting of object and i want to make If statement to make sure that if this object is not detect dont make any action and here is a pic of my object , if there any other object i want it to ignore
clear all
clc
box=imread('Box3.jpg');
c=rgb2gray(box);
boxPoints = detectSURFFeatures(c);
[boxFeatures, boxPoints] = extractFeatures(c, boxPoints);
figure,imshow(c);
a=webcam;
a.resolution= '640x480';
Obj=snapshot(a);
b=rgb2gray(Obj)
figure,imshow(b);
scenePoints = detectSURFFeatures(b);
[sceneFeatures, scenePoints] = extractFeatures(b, scenePoints);
boxPairs = matchFeatures(boxFeatures, sceneFeatures);
matchedBoxPoints = boxPoints(boxPairs(:, 1), :);
matchedScenePoints = scenePoints(boxPairs(:, 2), :);
[tform, inlierBoxPoints, inlierScenePoints] = ...
estimateGeometricTransform(matchedBoxPoints, matchedScenePoints, 'affine');
figure;
showMatchedFeatures(c, b, inlierBoxPoints, ...
inlierScenePoints, 'montage');
diff_im=imsubtract(Obj(:,:,1),rgb2gray(Obj));
diff_im=medfilt2(diff_im,[3,3]);
diff_im=im2bw(diff_im,0.18);
diff_im=bwareaopen(diff_im,300);
bw=bwlabel(diff_im,8);
props = regionprops(bw, 'Centroid','Orientation','BoundingBox');
figure, imshow(Obj)
hold on
center=props(1).Centroid;
plot(center(1), center(2), '-m+')
angle = props(1).Orientation
Rec= props(1).BoundingBox
rectangle('Position',Rec,'EdgeColor','r','LineWidth',2)
text(round(center(1))-50, round(center(2))+20, ['The Cenroid','(',...
num2str(round(center(1))), ',' , num2str(round(center(2))), ')'], 'BackgroundColor', [0 1 1]);
text(round(center(1))-50, round(center(2))+45, ['Rotation Angle from right horizontal',' ', num2str(angle)], 'BackgroundColor', [0 1 1]);
untitled3.jpg

1 个评论

here is an example i want to ingore no-similar object like that untitled.jpg

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by