Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Can anyone explain the loops in this code?
조회 수: 1 (최근 30일)
이전 댓글 표시
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');
댓글 수: 0
답변 (1개)
sloppydisk
2018년 5월 27일
편집: sloppydisk
2018년 5월 27일
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);
댓글 수: 0
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!