# Hi, can i know how to find the orientation of an object?

2 visualizaciones (últimos 30 días)
Nurul Farhana Mohd Fadzli el 13 de Mayo de 2022
Comentada: DGM el 14 de Mayo de 2022
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.
Can anyone help me with the algorithm and the development of coding?
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

DGM el 13 de Mayo de 2022
Editada: DGM el 13 de Mayo de 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.
% 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
thest = 6×1
15.9395 -13.5102 -10.8771 9.6239 -29.9191 29.2230
% 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 comentariosMostrar 3 comentarios más antiguosOcultar 3 comentarios más antiguos
Image Analyst el 14 de Mayo de 2022
You can use plot() to plot lines between the vertices.
DGM el 14 de Mayo de 2022
You just get the bounding boxes from regionprops() and plot them.
% 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

Iniciar sesión para comentar.

### Categorías

Más información sobre Geographic Plots en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by