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

조회 수: 10 (최근 30일)
Nurul Farhana Mohd Fadzli
Nurul Farhana Mohd Fadzli 2022년 5월 13일
댓글: DGM 2022년 5월 14일
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
Image Analyst
Image Analyst 2022년 5월 14일
You can use plot() to plot lines between the vertices.
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