Hi, can i know how to find the orientation of an object?
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I need to do a project that can identify the position and orientation of object on the conveyor so that the object will be in a right position/posture before being grab by the robotic arm.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/996395/image.jpeg)
Can anyone help me with the algorithm and the development of coding?
0 commentaires
Réponse acceptée
DGM
le 13 Mai 2022
Modifié(e) : DGM
le 13 Mai 2022
Well, here's this. It's not robust, but then again, the test image isn't a real process image either, so I'm going to consider it fair play.
inpict = imread('boxconvey.jpg');
% preprocess
inpict = imflatfield(inpict,20);
% binarize
mkrange = [0 1; 0.192 0.409; 0.742 1];
hsvpict = rgb2hsv(inpict);
M = all(hsvpict >= permute(mkrange(:,1),[2 3 1]),3) ...
& all(hsvpict <= permute(mkrange(:,2),[2 3 1]),3);
M = imfill(M,'holes');
M = imopen(M,ones(3));
M = imclose(M,ones(11));
imshow(M)
% get properties
S = regionprops(M,'centroid','image');
C = vertcat(S.Centroid);
numobj = numel(S);
% find number of apparent convex vertices
L = bwlabel(bwperim(M));
thest = zeros(numobj,1);
for k = 1:numobj
% calculate the object radius, sorted by angle
[y x] = find(L==k);
dv = [x y] - S(k).Centroid;
r = sqrt(sum((dv).^2,2));
th = atan2d(dv(:,2),dv(:,1));
[th idx] = sort(th);
r = r(idx);
% peak finding will probably be fragile
% good luck with that
[pk idx] = findpeaks(r,'minpeakprominence',8);
pkth = th(idx);
thest(k) = -mean([max(pkth(pkth<0)) min(pkth(pkth>=0))]);
end
thest
% demonstrate that the estimated angles are approximately correct
% by counter-rotating the object images
testimgs = cell(numobj,1);
for k = 1:numobj
th = thest(k);
thisimg = S(k).Image;
testimgs{k} = imrotate(thisimg,-th,'crop');
end
montage(testimgs)
I'm sure someone can come up with a better alternative, so I'll leave that to them.
5 commentaires
DGM
le 14 Mai 2022
You just get the bounding boxes from regionprops() and plot them.
inpict = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/996520/boxconvey.jpg');
% preprocess
inpict = imflatfield(inpict,20);
% binarize
mkrange = [0 1; 0.192 0.409; 0.742 1];
hsvpict = rgb2hsv(inpict);
M = all(hsvpict >= permute(mkrange(:,1),[2 3 1]),3) ...
& all(hsvpict <= permute(mkrange(:,2),[2 3 1]),3);
M = imfill(M,'holes');
M = imopen(M,ones(3));
M = imclose(M,ones(11));
S = regionprops(M,'centroid','image','boundingbox');
C = vertcat(S.Centroid);
numobj = numel(S);
% find number of apparent convex vertices
L = bwlabel(bwperim(M));
thest = zeros(numobj,1);
for k = 1:numobj
% calculate the object radius, sorted by angle
[y x] = find(L==k);
dv = [x y] - S(k).Centroid;
r = sqrt(sum((dv).^2,2));
th = atan2d(dv(:,2),dv(:,1));
[th idx] = sort(th);
r = r(idx);
% peak finding will probably be fragile
% good luck with that
[pk idx] = findpeaks(r,'minpeakprominence',8);
pkth = th(idx);
thest(k) = -mean([max(pkth(pkth<0)) min(pkth(pkth>=0))]);
end
% draw bounding boxes
imshow(M); hold on
for k = 1:numobj
thisbb = S(k).BoundingBox;
boxx = thisbb(1) + [0 thisbb(3)];
boxy = thisbb(2) + [0 thisbb(4)];
plot(boxx([1 1 2 2 1]),boxy([1 2 2 1 1]))
end
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Robotics dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!