您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 管理学资料 > matlab-红灯检测
MatlabHSV域区域色彩判定(可用于红绿灯检测)(2011-05-1020:33:47)%红绿等检测程序,基于HVS空间%作者:ltx1215%日期:2011-04-12%主要功能描述:实现对红绿灯检测功能,将图像从RGB转换到HVS空间,%避免了普通RGB空间易于受到亮度影响判定结果的弊端。clear;closeall;Image_f=imread('pic.jpg');figure(1),imshow(Image_f);title('检测图像');%RGBTOHSVhsv_f=rgb2hsv(Image_f);H=hsv_f(:,:,1)*255;S=hsv_f(:,:,2)*255;V=hsv_f(:,:,3)*255;figure,imhist(uint8(H));[y,x,z]=size(Image_f);Red_y=zeros(y,1);Green_y=zeros(y,1);Yellow_y=zeros(y,1);fori=1:yforj=1:xif(((H(i,j)=0)&&(H(i,j)15))||((H(i,j)=245)&&(H(i,j)=255))&&(V(i,j)50)&&(S(i,j)30))%(V(i,j)255)&&(V(i,j)50)&&(S(i,j)30)Red_y(i,1)=Red_y(i,1)+1;%红像素点统计elseif(((H(i,j)=66)&&(H(i,j)130))&&(V(i,j)50)&&(S(i,j)30))%(V(i,j)255)&&(V(i,j)50)&&(S(i,j)30)Green_y(i,1)=Green_y(i,1)+1;%绿像素点统计elseif(((H(i,j)=20)&&(H(i,j,1)65))&&(V(i,j)50)&&(S(i,j)30))%(V(i,j)255)&&(V(i,j)50)&&(S(i,j)30)Yellow_y(i,1)=Yellow_y(i,1)+1;%黄像素点统计endendendMax_Red_y=max(Red_y)Max_Green_y=max(Green_y)Max_Yellow_y=max(Yellow_y)if((Max_Red_yMax_Green_y)&&(Max_Red_yMax_Yellow_y))Result=1;elseif((Max_Green_yMax_Red_y)&&(Max_Green_yMax_Yellow_y))Result=2;elseif((Max_Yellow_yMax_Green_y)&&(Max_Yellow_yMax_Red_y))Result=3;elseResult=4;endif(Result==1)disp('检测结果为红灯');elseif(Result==2);disp('检测结果为绿灯');elseif(Result==3)disp('检测结果为黄灯');elsedisp('检测失败');end
本文标题:matlab-红灯检测
链接地址:https://www.777doc.com/doc-5214703 .html