function cardNames=identifyMultipleCards(cardsImage)

% Ray Wagner
% Elec 301
% Gang Project

% This function will take the image of cards (single card 
% or multiple cards) and return a string specifying the 
% cards in the image.  The image must be represneted as
% a matrix of grayscale values represented as 8-bit unsigned
% integers.

% First, we will call the function findspot() on the input
% image.  This returns the coordinates of the upper-left-hand
% points of all the windows the function identifySingleCard
% will scan through.  These coordinates will be stored as the
% matrix ulcCoords.

ulcCoords=findspot(cardsImage);
ulcCoordsSize=size(ulcCoords);

% For each ULC ordered pair in the ulcCoords vector, we'll
% call the function identifySingleCard, which will take the
% coordinate and return a vector to be used in selecting 
% the suit and value of the card that ULC belongs to from two
% matrices of suit and value strings. Each of these returns will be 
% stored in the string matrix roughHandIndices:

numberULCs= ulcCoordsSize(1,1);
roughHandIndices=[];

for n=1:numberULCs
   inputCoords=ulcCoords(n,:);
   cardIndices=identifySingleCard(cardsImage,inputCoords);
   roughHandIndices=[roughHandIndices;cardIndices];
end


% It's possible that the findspot() function will return two ordered pairs
% for one card, so we need to check for duplicates in the 
% roughHandIndices vector.  

rhIsize=size(roughHandIndices);

handIndices=roughHandIndices(1,:);

if (rhIsize>1)
   for i=2:rhIsize(1,1)
      nextCard=roughHandIndices(i,:);
      alreadyThere=0;
      handIndicesSize=size(handIndices);
      for j=1:handIndicesSize(1,1)
         if (handIndices(j,1)==nextCard(1,1) & handIndices(j,2)==nextCard(1,2))
            alreadyThere=1;
         end
         
      end
      
      if alreadyThere==0
         handIndices=[handIndices;nextCard];
      end
   end
end


% Finally, the matrix of strings to be returned will be constructed:


suitNames=[' clubs   ' ;' diamonds' ;' hearts  ' ;' spades  '];


valueNames=['two  ' ;'three' ;'four '; 'five ' ;'six  '; 'seven' ;'eight' ; 
   'nine '; 'ten  '; 'jack '; 'queen'; 'king '; 'ace  '];

sizeHandIndices=size(handIndices);

nameAccumulation=[];

for i=1:sizeHandIndices(1,1)
   nameString=strcat(valueNames(handIndices(i,1),:),' of',suitNames(handIndices(i,2),:));
   nameAccumulation=strvcat(nameAccumulation,nameString);
end

cardNames=nameAccumulation;

   
   

