Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Can anyone explain the loops in this code?

1 Ansicht (letzte 30 Tage)
SURILA GUGLANI
SURILA GUGLANI am 27 Mai 2018
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
figure(2)
file1='Frame_0001.png';%Reference
I=imread(file1);
imshow(I)
J=rgb2gray(I);
K=imresize(J, [500 500]);
figure(3)
file2='Frame_0242.png';
P=imread(file2);
imshow(P)
Q=rgb2gray(P);
R=imresize(Q,[500 500]);
bbox1=edge(K,'canny');
bbox2=edge(R,'canny');
matched_data1=0;
matched_data2=0;
white_points=0;
black_points=0;
for a=1:1:500
for b=1:1:500
if (bbox1(a,b)==1)
white_points=white_points+1;
else
black_points=black_points+1;
end
end
end
for i=1:1:500
for j=1:1:500
if (bbox2(i,j)==1)
matched_data1=matched_data1+1;
else
matched_data2=matched_data2+1;
end
end
end
total_data=white_points;
matched_data=matched_data1;
traffic_density_percentage=abs((((matched_data-total_data)/total_data)*100)*6.5);
figure(4)
if (traffic_density_percentage>=0) && (traffic_density_percentage<15)
instruc = 'Zero Traffic, Green Light for 15 seconds';
display=insertObjectAnnotation(R, 'rectangle', [0 450 0 0], instruc);
imshow(display);
elseif (traffic_density_percentage>=15) && (traffic_density_percentage<32)
instruc = 'Low Traffic, Green Light for 40 seconds';
display=insertObjectAnnotation(R, 'rectangle', [0 450 0 0], instruc);
imshow(display);
elseif (traffic_density_percentage>=32) && (traffic_density_percentage<70)
instruc = 'Moderate Traffic, Green Light for 60 seconds';
display=insertObjectAnnotation(R, 'rectangle', [0 450 0 0], instruc);
imshow(display);
else (traffic_density_percentage >=70)
instruc = 'Heavy Traffic, Green Light for 90 seconds';
display=insertObjectAnnotation(R, 'rectangle', [0 450 0 0], instruc);
imshow(display);
end
print('first','-dpng','-r300');

Antworten (1)

sloppydisk
sloppydisk am 27 Mai 2018
Bearbeitet: sloppydisk am 27 Mai 2018
They're counting the number of white points, black points and matched data, but they could be replaced by using logical indexing, (for example for the first one):
white_points = sum(bbox1);
black_points = sum(~bbox1);

Produkte


Version

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by