# Help with coin counting from an image

50 views (last 30 days)
Patrick Rohrmoser on 29 Mar 2021
Hey guys,
I hope you can help me in this case. I want to calculate the amount of coins, so for example I have a 2€ and 1€ coin, then the result should be 3€. So far I can check the diameter of various BW images. As you can see in the code I set the range where the circles should be detected in respect to the min and max radius of the coins. My problem is when the distance to the coins is different then I get different diameters. Has anyone a good idea how to deal with this issue?
% _____________________________________________________________
% Clear content
clc;
clear all;
close all;
%______________________________________________________________
Amount = 0;
%Coins = imresize(Coins,0.3);
CoinsBinary = im2bw(Coins,0.15);
se = strel('disk',20);
open=imopen(CoinsBinary,se);
fill = imfill(open,'holes');
clearing = imclearborder(fill);
figure
imshow(clearing)
%*** Automatic measuring of the diameter ****
diameter = regionprops(clearing,'MinorAxisLength');
A_cell = struct2cell(diameter);
for j = 1:length(diameter)
r(j) = A_cell{j};
end
numCircles = length(centers)
figure
imshow(Coins)
% Just for checking if it works to calculate the sum like this....
for i = 1:numCircles
Amount = Amount + 0.1;
Amount = Amount + 0.2;
Amount = Amount + 1;
Amount = Amount + 0.5;
Amount = Amount + 2;
end
end
fprintf('Total amount of coins: %.2f €', Amount);

Madhav Thakker on 14 Apr 2021
Hi Patrick,
I understand you want to classify each object (coin in your case) and then do some processing (adding the values). If you are not getting good results with standard Image processing techniques, you can look into https://in.mathworks.com/help/vision/ug/getting-started-with-object-detection-using-deep-learning.html deep learning solutions for object detection and classification.
Hope this helps.