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

testmain2.m
%vid=videoinput('winvideo',1,'I420_640x480'); 
%preview(vid); pause(3);

%initialization
bot_loc=6;

%aquisition
%img=getsnapshot(vid);
%im=ycbcr2rgb(img);
im=imread('imf.jpg');
imshow(im)
%get arena
gray=rgb2gray(im);
%caliberate1(trial and error.. important)
imt=niblack(gray,0.1,121);
imbw=im2bw(imt);
%se=strel('square',3);
%im_er=imerode(imbw,se);
are = medfilt2(imbw,[3 3]);
%end of get arena
o=get_ore(~are);
%o=4;
%get wall
imred=im(:,:,1);
imgrn=im(:,:,2);
imwall=imred-imgrn;
%direct caliberation
wall=im2bw(imwall,0.3922);
imshow(wall)
%   0.3922=100/255... quite optimum for red regions with pixel value 100
%end of get wall

%image properties
im_eroded=imerode(are,strel('square',3));
are3=imrotate(im_eroded,3);
%test 1 should be =31
[wall_lab,test]=bwlabel(are3,4);
imtool(wall_lab)
prop=regionprops(wall_lab,'Centroid','Area');
%end of image properties 
adj_mat=getadmat(are,wall);

for i=1:5
    food=imread('foo2.jpg');
    foodloc=food_loc(food);
    [dist, path] = graphshortestpath(sparse(adj_mat), bot_loc, foodloc);
    [ mot, o ] = motion( path, dist, o );
    mot=char(mot)
    %REAL TIME STARTS NOWWWWWW
    %pic=getsnapshot(vid);
    %picrgb=ycbcr2rgb(pic);
    %picpro=get_are(picrgb);
    
    
    
    ii=1;
    jj=1;
    sz=size(mot,2);
    for ii=1:sz
    %temp=mot(i);
    
    p3=prop(path(jj)).Centroid;
    p4=prop(path(jj+1)).Centroid;
    ang1=angle2Points(p3,p4)
    %p2=lcen;
    %p1=scen;
    
    %pic=getsnapshot(vid);
    %picrgb=ycbcr2rgb(pic);
    %picpro=get_are(picrgb);
    [lcen scen]=get_cir(~are);
    cenbot=(lcen+scen)/2;
    %ang1=angle2Points(p4,p3);
    ang2=angle2Points(scen,lcen)
    ang=mod((ang2-ang1+2*pi),2*pi)*180/pi
    dis = sqrt( (cenbot(1)-p4(1)).^2 +  (cenbot(2)-p4(2)).^2 )
    
        if mot(ii)=='L'
            while(ang>15 && ang<345)
                if(ang>15 && ang<180)
                disp('L');
                else disp('R');
                end
                
                %pic=getsnapshot(vid);
                %picrgb=ycbcr2rgb(pic);
                %picpro=get_are(picrgb);
                [lcen scen]=get_cir(~are);
                %cenbot=(lcen+scen)/2;
                %ang1=angle2Points(p4,p3);
                ang2=angle2Points(scen,lcen)
                ang=mod((ang2-ang1+2*pi),2*pi)*180/pi
            end
        end
    
    
        if mot(ii)=='R'
            while(ang>15 && ang<345)
                if(ang>180 && ang<345)
                disp('R');
                else disp('L');
                end
                %pic=getsnapshot(vid);
                %picrgb=ycbcr2rgb(pic);
                %picpro=get_are(picrgb);
                [lcen scen]=get_cir(~are);
                %cenbot=(lcen+scen)/2;
                %ang1=angle2Points(p4,p3);
                ang2=angle2Points(scen,lcen)
                ang=mod((ang2-ang1+2*pi),2*pi)*180/pi    
            end
        end
    
        if mot(ii)=='F'
            %jj=jj+1;
            while(dis>10)
                disp('F');
                    if(ang<345 && ang>180)
                    disp('R');
                    end
                    if(ang>15 && ang<180)
                    %else
                    disp('L');
                    end
                %pic=getsnapshot(vid);
                %picrgb=ycbcr2rgb(pic);
                %picpro=get_are(picrgb);
                [lcen scen]=get_cir(~are);
                cenbot=(lcen+scen)/2
                p4
                %ang1=angle2Points(p4,p3);
                ang2=angle2Points(scen,lcen);
                ang=mod((ang2-ang1+2*pi),2*pi)*180/pi
                dis = sqrt( (cenbot(1)-p4(1)).^2 +  (cenbot(2)-p4(2)).^2 )
            end
            jj=jj+1;
        end
    end
    bot_loc=foodloc;
    user_entry = input('I AM STILL HUNGRY!!!! PLACE MORE FOOD AND ENTER');
end

Contact us