Bottle cap top end tracking and analysis
Show older comments
%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

Answers (1)
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*');
Categories
Find more on Region and Image Properties in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!