<< Chapter < Page Chapter >> Page >

Approach 2

function stopfind(stopcolor,name) ticstopcolor = imread(stopcolor); % import the picture stopcolor = imresize(stopcolor,[500,NaN]); % resize the picture stop = rgb2gray(stopcolor); % make it grayscalestop = edge(stop); % edge detector to get rid of extraneous elements and convert to 1's and 0'sstop = bwareaopen(stop,30); % get rid of all blobs too small to be important bounds = regionprops(stop, 'boundingbox'); % for all regions, find their boundscenters = regionprops(stop, 'centroid'); % for all regions, find their centre of mass areas = regionprops(stop, 'area');numBlobs = length(bounds); % find the number of retions regions = zeros(numBlobs,4); % create a matrix to hold all the region dataheight = zeros(numBlobs,1); centerpts = zeros(numBlobs,2);area = zeros(numBlobs,1); for n = 1:numBlobs %regions(n,:) = bounds(n).BoundingBox; % populate the matrix for each region height(n) = regions(n,4);centerpts(n,:) = centers(n).Centroid; % populate the center matrix for each blob area(n,:) = areas(n).Area;end % numsamecenters=1;for i = 1:numBlobs for j = i+1:numBlobsif(abs(centerpts(i,1)-centerpts(j,1))+abs(centerpts(i,2)-centerpts(j,2)) 10) %add a less than symbol in front of the 10 [cnx would not let me import the actual line]samecenters(numsamecenters) = i; numsamecenters=numsamecenters+1;end endend figureaxis ij imshow(stopcolor)hold on title(name);for n = 1:numsamecenters-1 samecenter = floor(centerpts(samecenters(n),:));abovept = [samecenter(1),floor(samecenter(2)-height(samecenters(n)))]; belowpt = [samecenter(1),floor(samecenter(2)+height(samecenters(n)))]; rightpt = [samecenter(1)-floor(regions(samecenters(n),3)/3),samecenter(2)]; left_pt = [samecenter(1)+floor(regions(samecenters(n),3)/3),samecenter(2)]; if checkColor2(abovept(1),abovept(2),stopcolor)if checkColor2(belowpt(1),belowpt(2),stopcolor) plot(samecenter(1)-regions(samecenters(n),3)/2,samecenter(2),'go',...'markersize',4.5*regions(samecenters(n),3)) endendend hold offtoc end

Approach 3

function findAll % Import the Templates%-------------------------------------------------------------------------- S = imread('Templates/S.jpg'); % S templateT = imread('Templates/T.jpg'); % T template O = imread('Templates/O.jpg'); % O templateP = imread('Templates/P.jpg'); % P template STOP_W = imread('Templates/STOP_W.jpg'); % stop sign with white backgroundSTOP_B = imread('Templates/STOP_B.jpg'); % stop sign with black background SPEED = imread('Templates/SPEED.jpg'); % speed limit signONEWAY = imread('Templates/ONEWAY.jpg'); % one way sign DNE = imread('Templates/DNE.jpg'); % do not enter sign%-------------------------------------------------------------------------- for k = 1:3sign = imread(strcat('Do_Not_Enter/',num2str(k),'.jpg')); % import the picturesign1 = rgb2gray(sign); % make it grayscale sign1 = edge(sign1); % edge detector to get rid of extraneous elements and convert to 1's and 0'ssign1 = bwareaopen(sign1,30); % get rid of all blobs too small to be important bounds = regionprops(sign1, 'boundingbox'); % for all regions, find their boundsnumBlobs = size(bounds); % find the number of regions numBlobs = numBlobs(1); % make that number a handy variableregions = zeros(numBlobs,4); % create a matrix to hold all the region datafor n = 1:numBlobs % regions(n,:) = bounds(n).BoundingBox; % populate the matrix for each regionend checkS = zeros(1,numBlobs); % matrix holding the correlations of each blob with the S templatecheckT = zeros(1,numBlobs); % ditto for the T template checkO = zeros(1,numBlobs); % ditto for the O templatecheckP = zeros(1,numBlobs); % ditto for the P template checkSTOP_W = zeros(1,numBlobs); % ditto for the white stop sign templatecheckSTOP_B = zeros(1,numBlobs); % ditto for the black stop sign template checkSPEED = zeros(1,numBlobs); % ditto for the speed limit templatecheckONEWAY = zeros(1,numBlobs); % ditto for the one way template checkDNE = zeros(1,numBlobs); % ditto for the do not enter templatefor n = 1:numBlobs cropped = imcrop(sign, regions(n,:)); % choose one of the regions and crop itcropped = imresize(cropped, [57 35]); % resize the image for correlation testingcheckR = corr2(cropped(:,:,1), S(:,:,1)); % check red correlation between cropped image and S templatecheckG = corr2(cropped(:,:,2), S(:,:,2)); % check green correlation between cropped image and S template checkB = corr2(cropped(:,:,3), S(:,:,3)); % check blue correlation between cropped image and S templatecheckS(1,n) = (checkR + checkG + checkB)/3; % sum the correlationscheckR = corr2(cropped(:,:,1), T(:,:,1)); % red for T template checkG = corr2(cropped(:,:,2), T(:,:,2)); % green for T templatecheckB = corr2(cropped(:,:,3), T(:,:,3)); % blue for T template checkT(1,n) = (checkR + checkG + checkB)/3; % sum the correlationscheckR = corr2(cropped(:,:,1), O(:,:,1)); % red for O templatecheckG = corr2(cropped(:,:,2), O(:,:,2)); % green for O template checkB = corr2(cropped(:,:,3), O(:,:,3)); % blue for O templatecheckO(1,n) = (checkR + checkG + checkB)/3; % sum the correlationscheckR = corr2(cropped(:,:,1), P(:,:,1)); % red for P template checkG = corr2(cropped(:,:,2), P(:,:,2)); % green for P templatecheckB = corr2(cropped(:,:,3), P(:,:,3)); % blue for S template checkP(1,n) = (checkR + checkG + checkB)/3; % sum the correlationscheckR = corr2(cropped(:,:,1), STOP_W(:,:,1)); % red for white stop sign templatecheckG = corr2(cropped(:,:,2), STOP_W(:,:,2)); % green for white stop sign template checkB = corr2(cropped(:,:,3), STOP_W(:,:,3)); % blue for white stop sign templatecheckSTOP_W(1,n) = (checkR + checkG + checkB)/3; % sum the correlationscheckR = corr2(cropped(:,:,1), STOP_B(:,:,1)); % red for black stop sign template checkG = corr2(cropped(:,:,2), STOP_B(:,:,2)); % green for black stop sign templatecheckB = corr2(cropped(:,:,3), STOP_B(:,:,3)); % blue for black stop sign template checkSTOP_B(1,n) = (checkR + checkG + checkB)/3; % sum the correlationscheckR = corr2(cropped(:,:,1), SPEED(:,:,1)); % red for speed limit templatecheckG = corr2(cropped(:,:,2), SPEED(:,:,2)); % green for speed limlit template checkB = corr2(cropped(:,:,3), SPEED(:,:,3)); % blue for speed limit templatecheckSPEED(1,n) = (checkR + checkG + checkB)/3; % sum the correlationscheckR = corr2(cropped(:,:,1), ONEWAY(:,:,1)); % red for one way template checkG = corr2(cropped(:,:,2), ONEWAY(:,:,2)); % green for one way templatecheckB = corr2(cropped(:,:,3), ONEWAY(:,:,3)); % blue for one way template checkONEWAY(1,n) = (checkR + checkG + checkB)/3; % sum the correlationscheckR = corr2(cropped(:,:,1), DNE(:,:,1)); % red for one way templatecheckG = corr2(cropped(:,:,2), DNE(:,:,2)); % green for one way template checkB = corr2(cropped(:,:,3), DNE(:,:,3)); % blue for one way templatecheckDNE(1,n) = (checkR + checkG + checkB)/3; % sum the correlations end% Nice display (uncomment all) %fprintf(strcat(num2str(k),':\n'));%fprintf(strcat('S: ', num2str(max(checkS)), '\n')); %fprintf(strcat('T: ', num2str(max(checkT)), '\n'));%fprintf(strcat('O: ', num2str(max(checkO)), '\n')); %fprintf(strcat('P: ', num2str(max(checkP)), '\n'));%fprintf(strcat('STOP_W: ', num2str(max(checkSTOP_W)), '\n')); %fprintf(strcat('STOP_B: ', num2str(max(checkSTOP_B)), '\n'));%fprintf(strcat('SPEED: ', num2str(max(checkSPEED)), '\n')); %fprintf(strcat('ONEWAY: ', num2str(max(checkONEWAY)), '\n'));%fprintf(strcat('DNE: ', num2str(max(checkDNE)), '\n\n'));% Useful display for copying and pasting into a table (uncomment one line at a time) %fprintf(strcat(num2str(max(checkS)), '\n'));%fprintf(strcat(num2str(max(checkT)), '\n')); %fprintf(strcat(num2str(max(checkO)), '\n'));%fprintf(strcat(num2str(max(checkP)), '\n')); %fprintf(strcat(num2str(max(checkSTOP_W)), '\n'));%fprintf(strcat(num2str(max(checkSTOP_B)), '\n')); %fprintf(strcat(num2str(max(checkSPEED)), '\n'));%fprintf(strcat(num2str(max(checkONEWAY)), '\n')); %fprintf(strcat(num2str(max(checkDNE)), '\n'));endend

Questions & Answers

A golfer on a fairway is 70 m away from the green, which sits below the level of the fairway by 20 m. If the golfer hits the ball at an angle of 40° with an initial speed of 20 m/s, how close to the green does she come?
Aislinn Reply
cm
tijani
what is titration
John Reply
what is physics
Siyaka Reply
A mouse of mass 200 g falls 100 m down a vertical mine shaft and lands at the bottom with a speed of 8.0 m/s. During its fall, how much work is done on the mouse by air resistance
Jude Reply
Can you compute that for me. Ty
Jude
what is the dimension formula of energy?
David Reply
what is viscosity?
David
what is inorganic
emma Reply
what is chemistry
Youesf Reply
what is inorganic
emma
Chemistry is a branch of science that deals with the study of matter,it composition,it structure and the changes it undergoes
Adjei
please, I'm a physics student and I need help in physics
Adjanou
chemistry could also be understood like the sexual attraction/repulsion of the male and female elements. the reaction varies depending on the energy differences of each given gender. + masculine -female.
Pedro
A ball is thrown straight up.it passes a 2.0m high window 7.50 m off the ground on it path up and takes 1.30 s to go past the window.what was the ball initial velocity
Krampah Reply
2. A sled plus passenger with total mass 50 kg is pulled 20 m across the snow (0.20) at constant velocity by a force directed 25° above the horizontal. Calculate (a) the work of the applied force, (b) the work of friction, and (c) the total work.
Sahid Reply
you have been hired as an espert witness in a court case involving an automobile accident. the accident involved car A of mass 1500kg which crashed into stationary car B of mass 1100kg. the driver of car A applied his brakes 15 m before he skidded and crashed into car B. after the collision, car A s
Samuel Reply
can someone explain to me, an ignorant high school student, why the trend of the graph doesn't follow the fact that the higher frequency a sound wave is, the more power it is, hence, making me think the phons output would follow this general trend?
Joseph Reply
Nevermind i just realied that the graph is the phons output for a person with normal hearing and not just the phons output of the sound waves power, I should read the entire thing next time
Joseph
Follow up question, does anyone know where I can find a graph that accuretly depicts the actual relative "power" output of sound over its frequency instead of just humans hearing
Joseph
"Generation of electrical energy from sound energy | IEEE Conference Publication | IEEE Xplore" ***ieeexplore.ieee.org/document/7150687?reload=true
Ryan
what's motion
Maurice Reply
what are the types of wave
Maurice
answer
Magreth
progressive wave
Magreth
hello friend how are you
Muhammad Reply
fine, how about you?
Mohammed
hi
Mujahid
A string is 3.00 m long with a mass of 5.00 g. The string is held taut with a tension of 500.00 N applied to the string. A pulse is sent down the string. How long does it take the pulse to travel the 3.00 m of the string?
yasuo Reply
Who can show me the full solution in this problem?
Reofrir Reply
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Street sign detection with template matching and edge detection methods. OpenStax CNX. Dec 19, 2011 Download for free at http://cnx.org/content/col11387/1.1
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Street sign detection with template matching and edge detection methods' conversation and receive update notifications?

Ask