Be Sociable, Share!

Matlab Demo Model 

Figure Below Shows the model to implement the Warning Sign Detection and Recognition Using Matlab (Version 7.5 or Above).

Matlab Demo Model

Matlab Demo Model

Traffic Warning Sign Templates 

Templates used for Matching sign recognition are build in present in Matlab you can access these templates using this command

vipwarningsigns_templates.mat.

There are total 9 templates which are shown as follows :

  • Detection templates are low in resolution to achieve high performance detection speed from video frames and Remember size of frame and size of image extracted from frame should be same.
  • Red pixel is a distinguish characteristic to detect the red traffic sign this demo uses this technique for sign detection.
  • There’s a problem of accuracy during detection so three templates are used for each sign detection which are oriented in different directions to detect the sign.
templates

templates

Detection of  Traffic Sign 

  • For the detection of sign each frame is analysed.
  • First the image is Converted into gray scale image and then threshold is performed.
  • Then by using blob analysis portion  of red part is extracted.
  • Then this extracted part is compared with each template.
  • If the template is matched with extracted part then a rectangle is drawn at the location of extracted part in that frame.
  • In this way rectangle is drawn at all the frames and at the end all frames are played using implay video command.

Recognition and display the Name of Traffic Sign 

  • Now when the template is  matched with extracted blob this is done by using correlation.
  • Each template is matched with extracted blob by correlating each template and extracted part.If there’s exactly or 50% match then a check is assigned that its completely matching with the extracted blob sign.
  • Now template is recognized Now the name of recognized sign is concatenated with the red sign.
  • Image of Sign is Deigned and will be provided With the Source Code.

traffic warning sign recognition

Matlab Code

function main
readerobj = mmreader(‘stoprd.avi‘);
vidFrames = read(readerobj);

numFrames = get(readerobj, ‘numberOfFrames’); %get number of frames
implay(vidFrames)                                        %Play Input Video Files
for k = 1 : numFrames-1
mov(k).cdata = vidFrames(:,:,:,k);      %Extract Frame & save in Struc
mov(k).colormap = [];
mov(k).cdata=blobAnalysis(mov(k).cdata);%Call Blob Analysis Function
vidFrames(:,:,:,k)=mov(k).cdata;           %Save Output Data
end
implay(vidFrames)                                                                                  

  • In the Main Function Video as input is read in readerobj  and then frames are extracted from video input.
  • These frames are passed into blobAnalysis function one by one
  • Output image after processed by blobAnalysis function is saved in vidFrames
  • And At last when all frames are received in vidFrames output video is played using implay which is last command in above code.

 

 Blob Analysis Function 

function x=blobAnalysis(a)
x=a;
a(:,:,1) = medfilt2(a(:,:,1), [3 3]);
a(:,:,2) = medfilt2(a(:,:,2), [3 3]);
a(:,:,3) = medfilt2(a(:,:,3), [3 3]);
[r c d]=size(a);
check=1;
i1=0;j1=0;
i2=0;j2=0;

for i=1:r
for j=1:c

if(a(i,j,1)>125&&a(i,j,2)<90&&a(i,j,3)<90)
if(check)
i1=i;j1=j;
check=0;
else
i2=i;j2=j;
end

end

end

end

i1=i1-2;
if(i1<1) i1=1; end i2=i2+2; if(i2>r)
i2=r;
end

if(c>500)

j1=j1-40;
else
if(r<150)
j1=j1-10;
else
j1=j1-30;
end
end
if(j1<1) j1=1; end j2=j2+20; if(j2>c)
j2=c;
end
i2-i1;

yieldtag=imread(‘yieldtag1.jpg’);
stptag=imread(‘stoptag1.jpg’);
[r1 c1 d1]=size(stptag);
z=a(i1:i2,j1:j2,1:3);

z=rgb2gray(z);
z=im2double(z);
z=im2bw(z,0.5);
[row col]=size(z);
if(row~=0 && col~=0)
z=imresize(z, [18 18], ‘nearest’);
load vipwarningsigns_templates.mat;
for k=1:9
temp=template_recognition(:,:,k);
s(k)=corr2(temp,z);
end
mx=max(s);
ind=1;
for i=1:9
if(s(i)==mx)
ind=i;
end
end
if(isnan(s)==0)
if(i2-i1>20)
if(mx>0.15)
for l1=i1:i2
a(l1,j1,1)=255;
a(l1,j1,2)=255;
a(l1,j1,3)=0;

a(l1,j2,1)=255;
a(l1,j2,2)=255;
a(l1,j2,3)=0;
end

for l2=j1:j2
a(i1,l2,1)=255;
a(i1,l2,2)=255;
a(i1,l2,3)=0;

a(i2,l2,1)=255;
a(i2,l2,2)=255;
a(i2,l2,3)=0;
end
if(r<150)

scalex=i2+r1-1;
scaley=j1+c1-1;
a(i2:scalex,j1:scaley,:)=yieldtag;
else
scalex=i2+r1-1;
scaley=j1-c1+1;
a(i2:scalex,scaley:j1,:)=stptag;
end

end
end
end
end
x=a;

  • Now our frames are coming in variable a and from a to x.
  • Now applying median filter on the frame on all three dimensions that’s red blue and green using MEDFILT2  for smoothing as some frames are blurry.
  • Now doing BLOB ANALYSIS to extract red region from frame by by checking intensity values for red when intensity values for dimention1>125 && dimention2 <90 && dimention3<90 then its mean we are in red region so when loop enter into this red region we note this pixel in variable (i1,j1) and in the same way when loop leave this this red part we note this pixel in variables (i1,i2).
  • Now we know entry and ending points of this region now added a little offset in entry and end red pixel to extract that red part from the frame and now our extracted traffic sign is in variable z.
  • Now reading images that’s tags to display the recognized sign that’s yieldtag and stptag.
  • Now converting the extracted red sign which was in z variable into gray ,double and Thresholding  using RGB2GRAY , IM2DOUBLE , IM2BW Command.
  • Now resizing the extracted image size to the size template for matching using IMRESIZE command.
  • Now loading template sign to match with the extracted sign which is in variable z by this command load vipwarningsigns_templates.mat;
  • Now Reading each template in temp variable and finding correlation of each template with red extracted sign from frame which is in variable z.
  • Now s variable contains all correlation result now find max of correlation  now we found template which is matching with the traffic sign.
  • Now adding a image tag with the recognized sign.
  • Now finally drawing rectangle on the frame and frame is returned

Output

traffic sign recognition video

traffic sign recognition video

traffic sign recognition video Results

traffic sign recognition video Results

Source Code

Like , share this post on Facebook , Twitter by using left moving Social Sharing block and follow us on Facebook Page , Twitter and do comment and enter your email. After you have done you will automatically get source code in your mail. Note : This will be auto generated mail you can’t get until you follow above method.

 

 

 

Be Sociable, Share!