Code covered by the BSD License  

Highlights from
Automata Engineer 2010 NITK- Documented version

image thumbnail

Automata Engineer 2010 NITK- Documented version

by

 

The documented version of the code which solves the problem statement of Automata Engineer 2010 NITK

detround( bw )
function [ met, stats, leb, dir, circen ] = detround( bw )
met=[0 0 0 0 0 0 0 0 0 0 0 0];
leb=[0 0];
%dir='n';
%area=[0 0];
%cent=[0 0];
i=1;

%returns the circular objects in the image
%Input: the inverted filtered image of the arena so that the circular
%       objects are white.
%Output: met: matrix which return the percent of roundness of each circular
%       object
%       stats: the property matrix of the circular objects
%       leb: labelled matrix
%       dir: gives the orientation of the bot left, right, front, or back
%       circen: in this case, it is the centroid of the two circles
%           present in the area
   
% remove all object containing fewer than 10 pixels
bw = bwareaopen(bw,10);

[B,L] = bwboundaries(bw,'noholes');


stats = regionprops(L,'Area','Centroid');

%threshold = 0.94;
imtool(bw)
% loop over the boundaries
for k = 1:length(B)

  % obtain (X,Y) boundary coordinates corresponding to label 'k'
  boundary = B{k};

  % compute a simple estimate of the object's perimeter
  delta_sq = diff(boundary).^2;
  perimeter = sum(sqrt(sum(delta_sq,2)));

  % obtain the area calculation corresponding to label 'k'
  area = stats(k).Area;

  % compute the roundness metric
  metric = 4*pi*area/perimeter^2;
  if (metric>0.8 && metric<1.2)
      leb(i)=k;
      %area(i)=stats(k).Area;
      %cent(i)=stats(k).Centroid;
      i=i+1;
  end
      
  %met(1,k)=metric;


end

%title(['Metrics closer to 1 indicate that ',...
 %      'the object is approximately round']);

if(stats(leb(1)).Area > stats(leb(2)).Area)
   lcen=stats(leb(1)).Centroid;
   scen=stats(leb(2)).Centroid;
else
   lcen=stats(leb(2)).Centroid;
   scen=stats(leb(1)).Centroid;
end
circen=[lcen scen];
if((scen(1)-lcen(1)>25) && abs((scen(2)-lcen(2))<5))
    dir='l';
elseif((lcen(1)-scen(1)>25) && abs((lcen(2)-scen(2))<5))
    dir='r';
elseif((scen(2)-lcen(2)>25) && abs((lcen(1)-scen(1))<5))
    dir='u';
elseif((lcen(2)-scen(2)>25) && abs((lcen(1)-scen(1))<5))
    dir='d';
else dir='\0';
end

    
    % else retake image and try
    
    
end

Contact us