How to label coins after recognizing them?
Show older comments
Hi everyone! I hope everything is great.
I have a question about coin recognition. I'm new to image processing and I'm trying to recognize the coins, label them and calculate the total amount.
Here is my code;
img = imread('bp3.jpg');

I = rgb2gray(img);
imshow(I)
bw = imbinarize(I);
figure; imshow(bw)
bw = bwareaopen(bw, 400);
figure; imshow(bw)
se = strel('disk', 3);
bw = imclose(bw, se);
bw = imfill (bw, 'holes');
figure; imshow(bw);
[r, num] = bwlabel(bw);
prop = regionprops('table',bw,{'Area','centroid'});
% kurus5=0;
% kurus10=0;
% kurus25=0;
% kurus50=0;
% tl1=0;
total=0;
for i=1:num;
switch logical(true)
case prop.Area(i)> 1.4e+06
rgb = insertText(I,[prop.Centroid(i,1) prop.Centroid(i,2)],'1tl','FontSize',48,'TextColor','black');
total=total+1;
%tl1=tl1+1;
case prop.Area(i)>1.2e+06 && prop.Area(i)<1.4e+06
rgb = insertText(I,[prop.Centroid(i,1) prop.Centroid(i,2)],'50kr','FontSize',48,'TextColor','black');
total=total+0.5;
%kurus50=kurus50+1;
case prop.Area(i)>8.7e+05 && prop.Area(i)<1.2e+06
rgb = insertText(I,[prop.Centroid(i,1) prop.Centroid(i,2)],'25kr','FontSize',48,'TextColor','black');
total = total + 0.25;
%kurus25=kurus25+1;
case prop.Area(i)>6.4e05 && prop.Area(i)<8.7e05
rgb = insertText(I,[prop.Centroid(i,1) prop.Centroid(i,2)],'10kr','FontSize',48,'TextColor','black');
total = total + 0.10;
%kurus10=kurus10+1;
otherwise
rgb = insertText(I,[prop.Centroid(i,1) prop.Centroid(i,2)],'5kr', 'FontSize',48,'TextColor','black');
total = total + 0.05;
%kurus5=kurus5+1;
end
end
subplot; imshow(rgb)
title(['Total Amount:',num2str(total),'TL'])
I can calculate the total amount but the problem is I can't label them all. Only one of the labels is shown. (It is 5kr for this example.) And let say if I delete '5kr' part, then only '10kr' label would shown. However I can't show them all at once.
I don't know how to fix that and I'd be glad if you can help me. Thanks in advance.
2 Comments
Jan
on 17 Jun 2022
This is a really bad idea:
switch logical(true)
On one hand, true is a logcial already, so casting it again is a waste of time. On the other hand, your code is working with the switched switch conditions, but this is at least confusing.
The case prop.Area(i)==1.4e+06 is unlikely, but not ibncluded in your code.
What is the purpose of the orphaned subplot; command?
Aysenur Atagün
on 17 Jun 2022
Accepted Answer
More Answers (0)
Categories
Find more on Semantic Segmentation 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!