Bottle cap top end tracking and analysis

2 次查看(过去 30 天)
%Greetings friends, I need to be able to graph the top of the bottle all the way around. I already did it with the geometric centroid of the bottle, %but I can't get a code to follow the ''bottle cap''. I leave here the code of the centroid
%%
Mmax = max(seq,[],3);
%Mmin = min(seq,[],3);
MinArea = %minimum area in square pixels, determined after analyzing a video
Mtaco = [];
for ii = 1:length(Dir)
ImBW = double(Mmax) - double(seq(:,:,ii)) > 1500; %binarization
s = regionprops(ImBW,'Area','Orientation','Centroid'); %function regionprops
kk = [s.Area] > MinArea; %filter objects other than the bottle
s = s(kk);
% %if sum(kk) == 1
%
imagesc(seq(:,:,ii)), axis image, colormap gray, pause(0.01)
hold on
%contour(seq(:,:,ii),[100 100],'LineWidth',2,'Color','y')
for ss = 1:length(s)
A = s(ss).Centroid;
plot(A(1), A(2),'mo'), title(['Im ' num2str(ii)]), pause(0.1),
Mtaco = [Mtaco; ii s(ss).Area s(ss).Centroid s(ss).Orientation];
end
hold off
end

回答(1 个)

yanqi liu
yanqi liu 2022-2-16
yes,sir,may be use the area property to get the target,such as
im = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/890945/image.png');
im2 = imcrop(im, [201 120 482 451]);
bw = ~im2bw(im2, 0.3);
bw = bwareaopen(imclearborder(bw), 20);
bw = bwareafilt(bw,1,'smallest');
stats = regionprops(bw);
figure; imshow(im2, []);
hold on; rectangle('position', stats(1).BoundingBox, 'EdgeColor', 'r', 'LineWidth', 2)
plot(stats(1).Centroid(1), stats(1).Centroid(2), 'r*');

类别

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

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by