UXDE dot Net

Traffic Warning Sign Recognition Matlab Code

By -

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.

 

 

 

Farheen Bibi

You can find Farheen on , and .

145 Comments to Traffic Warning Sign Recognition Matlab Code

  1. Hai Khan,

    Thanks for the help.
    I would like to know more about the solution; especially on how to recognize more specific traffic signs.

    Regards

    • Yea sure let me know if you need the source code i will send it to you in your mail and to recognize other object you have to make templates of that object but here i am just using Matlab built in templates using this commannd load vipwarningsigns_templates.mat;

      • thuong nguyen van

        hi ammadkhan
        do you have an code to detect and track color in live camera? I using matlab
        or do you have any suggestion.
        thank you very much

        • In this sign recognition I detected red color if you read the whole article you will get know how to detect red color. In the same way you can detect any color of your choice If you do effort to understand the algorithm. First try this on a video clip instead of testing it on live camera.

      • hi ammad
        i wanna find out the convex hull of any object as i took a palm picture in my project there was a code that i get from internet for impcon.bmp image when same code i m trying to run for my image it is giving an error of Index exceeds matrix dimensions so please help me to find the convex hull of any binary image using the set of structuring elements …..PLEASE

  2. dhinagaran

    u done this project in good manner

    i need to understand it briefly

    could u send this source code ?…

    thanks in advance

    • Thanks for your Appreciation first i would suggest you to open matlab
      1) click on start on left below go into Blocksets —>Video And Image Processing —->Demo
      2) After this in this category click on Traffic warning sign recognition

      Now in this Demo first understand the whole procedure and then come towards the code section to understand authentically then let me know if you have any problem
      Check your mail for Source code

  3. Thanks for the source code. There is an error like
    Error using load
    Unable to read file vipwarningsigns_templates.mat: No such file or directory.

    How can I have “vipwarningsigns_templates.mat”?

    • Use this command to load these files First check this command on console command window to know the variables
      load vipwarningsigns_templates.mat
      who

      variables will be as follows i am copying here OUTPUT OF Above Command

      Name Size Bytes Class Attributes

      template_detection 12x12x3 1728 single
      template_detection_display 12×36 1728 single
      template_ids 1×9 36 single
      template_names 3×12 36 uint8
      template_recognition 18x18x9 11664 single
      template_recognition_display 18×162 11664 single

  4. But it can not be loaded.
    the error is :
    Error using load
    Unable to read file vipwarningsigns_templates.mat: No such file or directory.
    You mean before running the code I should use this command?

    load vipwarningsigns_templates.mat
    who

  5. Do you code processing image for Identify traffic signs using Support Vector Machines ?
    I need document and code.can you help me?
    Thank you very much!

    • Right Now i am very busy in my Engineering exams but soon i will do some research on Support Vector Machines and make a new tutorial regarding Recognition algorithm

  6. Do you code processing image for Identify traffic signs using Gabor Filter ?
    I need document and code. can you help me?
    Thank you very much!

    • It would take time now a days i am really busy i have to prepare my self for exams you can examine this code this is developed using blob analysis .If you can understand this just alter the code insert your technique and if do you need it ? i will mail you just inform me

  7. Could you please send me your project Traffic Warning Sign Recognition Matlab Code. I want to develope it on Android base on your project.
    Thank you so much.

  8. Shakhil Dhotah

    hi Mr Khan,
    Traffic sign detection and recognition is quite difficult to implement on matlab if one is not really familiar to this programming tool. well , actually part of my thesis is on that, and i will have to use that to make use of traffic speed signs detection. Can you please send me the code please.

        • IN blob analysis we need to extract red part from the image to see the RGB intensities of image Use IMTOOL command and move your mouse cursor over red area then you will get know intensities and these intensities you will use here
          if(a(i,j,1)>125&&a(i,j,2)<90&&a(i,j,3)<90)
          now when this condition is true this means loop reaches to red part and you will insert a check on start of red part and when this condition becomes false we note these pixels in this we get know starting and ending pixels of red traffic sign which will be in variables
          starting = (i1,j) starting means start of red pixel in image
          ending = (i2,j2) ending means end of red pixel in image

          now we add an offset and insert a rect for more understanding please read all post and try to understand the flow and if you do not understand any logic comment about specific line to understand

    • first you have to make template just like template for the stop sign by extracting frame from the video and from frame crop the part which you want to recognize in the .avi video after then use that template in the code and apply the corresponding functions which were applied for the demo traffic warning sign Recognition

  9. Hello Ammad,
    I have detected a speed limit traffic sign but to recognised it i have to use OCR. My detected image contains some noise along with traffic sign. How can i completely detect the circular sign using “regionprops” command?

    • you can do blob analysis just like i did blob analysis recognizes round red part and coorelation is used to recognize sign that is coorelate with the template and for noise smooth the image by applying averaging filter

  10. Please explain for me why you use if(mx>0.15) in BlobFunction?
    How can you find 0.15?
    Thank you so much!

  11. Hi, could you forward me your source code? I’m also experiencing some difficulties on this topic. Thanks!

      • But we interest in only speed signs. First, we find red areas in the picture or video. Then we want detecting areas which are circle. In this way, we detect the traffic speed sign. Then we will detect amount of speed with using character recognition.

        • Yes you are at right place to find the red areas you have to do analysis to find that red part so i am sending you the source code in which used the same technique of detecting red areas which are in circle you can modify this source code but i want you to keep me updating about your project and also after completing this we will be thankful if you share this with us thanks keep visiting and if you want to keep your self upto date join this page https://www.facebook.com/MatlabProgramming @crunchmodo

          • thanks a lot :) we already found red areas before your project. Is this area circle, we couldn’t. Metric value or correlation, we tried but unfortunatelly. How can we detect circle areas, what do you tkink?

  12. I am working on a traffic sign board recognition system. It should perform canny edge detection, hough transform for circle detection and LDA for comparison of the input image with the images in the database. Can you please help me?

    • You should first check this project in this project we do analysis to detect edges of red circular board using blob analysis and then comparison is made with image using Co Relation do you need this code ?

      • I have completed the edge detection portion using Canny. Now I am working on Hough transform for detecting the circular shapes in the edge detected image. I know that your code will work. But I want to try some new combination of algorithm for the same problem. I want to use LDA instead of Co-relation. Is that possible? I am actually confused in case of LDA, how to give input, what will be the output etc. Can you help me on this?

  13. Elrick Terry

    Hi!
    I’m starting to research about traffic recognition.
    I’m very interested on your project to have an idea on how to start to study this.
    In the next two months I want to detect signales only on static images and tag the signal
    Thank you in advance!

  14. hi
    i am a computer and communication engineering student, i working on a project similar to yours i am trying to recognize road signs and compare them with saved ones in matlab so if you may send me the source code of your program i will be thankful.

    thanks

      • what i am unable to do is to compare two pictures i have already succeeded to import picture from the web cam and turn in into the grey (intenstity) color what i missed is how to compare this picture with a saved ones on simuink

        • you can compare two pictures by using co-relation co-relation check the matchings of pixel use this
          R = CORR2(A,B) computes the correlation coefficient between A
          and B, where A and B are matrices or vectors of the same size.
          Example :
          if ur image is is not good apply median filter other wise its fine
          ——-
          I = imread(‘anyimage.tif’);
          J = medfilt2(I);
          R = corr2(I,J)

  15. hi khan, im paresh. im trying to run this code, but get an error msg.

    code.
    ///////////////////////////////////////////////////////////////////////////////////////////////////////
    a = imread(‘image1.jpg’); %reading images as array to variable ‘a’ & ‘b’.
    b = imread(‘image2.jpg’);
    c = corr2(a,b); %finding the correlation btwn two images
    if c==1
    disp(‘The images are same’)%output display
    else
    disp(‘the images are not same’)
    end;

    error.
    /////////////////////////////////////////////////////////////
    Error using ==> mtimes
    Input arguments must be 2-D.

    Error in ==> corr2 at 26
    r = sum(sum(a.*b))/sqrt(sum(sum(a.*a))*sum(sum(b.*b)));

    Error in ==> correkation at 3
    c = corr2(a,b); %finding the correlation btwn two
    images

    ??? Error using ==> mtimes
    Input arguments must be 2-D.

    Error in ==> corr2 at 26
    r = sum(sum(a.*b))/sqrt(sum(sum(a.*a))*sum(sum(b.*b)));

    Error in ==> correkation at 3
    c = corr2(a,b); %finding the correlation btwn two
    images

    ??? Error using ==> mtimes
    Input arguments must be 2-D.

    Error in ==> corr2 at 26
    r = sum(sum(a.*b))/sqrt(sum(sum(a.*a))*sum(sum(b.*b)));

    Error in ==> correkation at 3
    c = corr2(a,b); %finding the correlation btwn two
    images

    >>

  16. hey mate, hope you’re good.. well don’t you have any algorithm for Circular/ellipse hough transform for video processing… actually i’m trying to make a speed limit sign recognition, i did convert RGB to Grayscale ,also extract the red part (since i am planning to detect only the prohibition signs), performed morphological process, but now i’m stuck with the hough transform… Any help please

  17. Peter Chang

    Hello Khan,

    Excellent work! Would you kindly send me the source code? I am working on a similar problem.

    Thanks.

    Regards,
    Peter Chang

  18. Hi, good work I’m interesting by the road signs detection and recognition. Could you send me the source code please ?

    Thank you,

    david81

  19. mide david

    Hi Khan, this is great to finally find some one using matlab for traffic sign recognition. My research has made me find mostly face recognitions and other types. I am a student of Information engineering and I am working on a project for ANN used for road sign recognition.Please canI have the source codes for the blob analysis method you used?..I was tryinng to work with the PCA for face recognition and tried to adjust for road signs, but because i am just learning matlab, its difficult. Could you help out?

  20. mide david

    Hi Khan, I am quite happy to find a place where someone talks about traffic sign recognition. Please can i get the source codes? I am a student on information engineering and I am working on a project on road sign recognition using NN’s.I am also very new to matlab but started getting my way around. could you help/

  21. i copied the code above and made it run but its not running giving errors such as
    Error: File: main.m Line: 5 Column: 28
    The input character is not valid in MATLAB statements or expressions.
    kindly help

  22. Hi Ammadkhan,

    First I want to help you for sharing your project and knowledge.
    I am very interested in this subject and I would like to know more about this.
    Can you please send me the source code and I would be very happy if you could tell me which tools do I need and which versions.

    Thank you in advance!
    Andrea

  23. Adeel Rafiq

    Hi Ammad Khan,

    Hopefully you are doing well.

    I did as u said. Kindly email me this source code.

    I am working on Foggy Sign board.
    In pre-processing i am working on MSRCR.
    After pre-processing your code will help to complete my task.

    Kindly email me and suggest me if u have pre-processing MSRCR source code.

    rafiq.adeel@yahoo.com

    Thanks

  24. hello when i run this code i get an error saying
    File “yieldtag1.jpg” does not exist.
    and also
    Error in ==> project at 10
    mov(k).cdata=blobAnalysis(mov(k).cdata);%Call Blob Analysis Function

    what is the reason behind this?

Leave a Reply