%Seth Eatinger

%-----------------------------------------------------------
%scanit()
%
% The image has already been run through the Roberts edge masking filter.  The scanit() function will scan
%the processed image in a convolution/rasterization pattern to find the corners of the cards (Upper left and lower right).
%A detection window of 30x50 is scanned in the following manner:
%
%First, then Across -->
% ||
% \/
%
%In each 30x50 detection window, the number of edge pixels are summed.  If this sum is greater than a set threshold,
%then this window is saved as a possible dection of a corner of the card.  The row and column value of
%the upper left corner of detection window is saved.
%



function [sweet] = scanit(edgeimage)

threshold = 215;      %Threshold for the number of edge pixels found in the detection window.
winheight = 50;       %Height of the detection window.
winwidth = 30;        %Width of the detection window.
n = 0;

edgeimage = double(edgeimage);

dim = size(edgeimage); %Find the dimensions of the image.
r = dim(1,1);
c = dim(1,2);

for j = 1:c-winwidth,
   for i = 1:r-winheight,
      
      window_sum = sum( sum ( edgeimage(i:i+winheight-1,j:j+winwidth-1)));  %Sums the edge pixels in the detection window.
      
      if window_sum >= threshold %If the sum of edge pixels in the detection window
                                 %is greater than the threshold value, store the window.
         n = n + 1;
         sweet(n,1) = i;
         sweet(n,2) = j;
         
      end
   end
end



