资源简介
hsv_f = rgb2hsv(g4);
H = hsv_f(:,:,1)*255;
S = hsv_f(:,:,2)*255;
V = hsv_f(:,:,3)*255;
[y,x,z]=size(g4);
Red_y=zeros(y,1);
Green_y=zeros(y,1);
Yellow_y=zeros(y,1);
for i=1:y
for j=1:x
if(((H(i,j)>=0)&&(H(i,j)50)&&(S(i,j)>30))
Red_y(i,1)= Red_y(i,1)+1;
elseif(((H(i,j)>=105)&&(H(i,j)50)&&(S(i,j)>30)) Green_y(i,1)= Green_y(i,1)+1;
elseif(((H(i,j)>=45)&&(H(i,j,1)50)&&(S(i,j)>30)) Yellow_y(i,1)= Yellow_y(i,1)+1;
end
end
end
Max_Red_y=max(Red_y);
Max_Green_y=max(Green_y);
Max_Yellow_y=max(Yellow_y);
if (Max_Red_y>Max_Green_y)&&(Max_Red_y>Max_Yellow_y)
disp('红灯');
else if (Max_Green_y>Max_Red_y)&&(Max_Green_y>Max_Yellow_y)
6/7页
disp('绿灯');
else if(Max_Yellow_y>Max_Red_y)&&(Max_Yellow_y>Max_Green_y) disp('黄灯');
end
end
End
评论
共有 条评论