from Real time coin counter by abhilash harpale
the program takes video input from a camera and counts the coins present in the frame.

coincounter.m
%Copywrite Abhilash Harpale (c) 2009
% coincounter:

% set coins against dark, nonreflective  background
% Do not overlap coins
% Illuminate the coins with a light source.

vid=videoinput('winvideo',1);
triggerconfig(vid,'manual');
set(vid,'FramesPerTrigger',1);
set(vid,'TriggerRepeat', Inf);
set(vid,'ReturnedColorSpace','rgb');
start(vid);
i=0;
num=zeros(1,2);
while(1)
    trigger(vid);
    f=getdata(vid,1);
    g=regwht(f,125);
    g=imadjust(g,[0 1],[1 0]);
    g=imfill(g,'holes');
    w=strel('disk',15);
    g=imerode(g,w);
    g=imopen(g,w);
    %imshow(g);
    %disp('frame number:');
    %disp(i);
    [l num(1,mod(i,2)+1)]=bwlabel(g);
    if (num(1,1)~=num(1,2))
       disp('number of coins=');
       disp(num(1,mod(i,2)+1));
    end
    i=i+1;
end
      
 
       
    

    

Contact us at files@mathworks.com