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

10 次查看(过去 30 天)
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?

采纳的回答

DGM
DGM 2022-5-13
编辑:DGM 2022-5-13
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
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 个评论
DGM
DGM 2022-5-14
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Geographic Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by