资源简介

一种基于亮度和颜色阈值的尾灯匹配识别算法,可用于夜间尾灯检测

资源截图

代码片段和文件信息

clc;
clear;
fileName=‘one.avi‘;
obj=VideoReader(fileName);
nframes=get(obj‘Numberofframes‘);

mov(1:nframes) = struct(‘cdata‘ []...                     
                        ‘colormap‘ []);
                    
I=read(obj1);
carweideng=zeros([size(I1) size(I2) 3 nframes]class(I));       % 每帧数据格式

tic;
for u=1:nframes
        A=read(obju);       % 存一幅600*480的彩色图像  600*480*8*3=7Mb  如果用乒乓缓存*2=14Mb   
        R=A(::1);
        G=A(::2);
        B=A(::3);
        
        [rowcolumn]=size(R);
        if u==1                      % 切割后找不到尾灯需重新整幅图像寻找
        %L=zeros(rowcolumn3);
        for i=1:row
            for j=1:column   
        %         if(R(ij)>220&&R(ij)-G(ij)>20&&R(ij)-B(ij)>20)    % 红色区域条件
        %               L(ij1)=R(ij);
        %               L(ij2)=G(ij);
        %               L(ij3)=B(ij);
        %            else  if(R(ij)>220&&G(ij)>220&&B(ij)>220)      %  白色区域条件
        
        %找出白色高亮区域
                 if(R(ij)>235&&G(ij)>235&&B(ij)>235) 
                      L(ij1)=R(ij);
                      L(ij2)=G(ij);
                      L(ij3)=B(ij);

                else
                   L(ij1)=0;
                   L(ij2)=0;
                   L(ij3)=0;
         %           end
                end
            end
        end

        % L=cat(3L1L2L3);
        L=uint8(L);
%        imshow(L)

        % 形态学处理
        bw=im2bw(Lgraythresh(L));    % L其实就相当于黑白图像,阈值其实可随便取
        bw=imclearborder(bw8);
        D=bwareaopen(bw10);      %  删除白色小面积区域
        E=bwareaopen(D1000);     %  删除白色大面积区域
        Q=imsubtract(DE);
 %       imshow(Q)
        [L1num]=bwlabel(Q8);      % 标记连通区域
        
        % 寻找白色连通区域周围红色像素满足条件的标记区域
        count=zeros(1num);
        t=0;
        for k=1:num
            [mn]=find(L1==k);
            xmax=max(m);
            xmin=min(m);
            ymax=max(n);
            ymin=min(n);
            if(xmin-6<1|xmax+6>row|ymin-6<1|ymax+6>column)
                count(k)=0;
            else
                for i=xmin-6:xmax+6             %红色区域寻找范围选择
                    for j=ymin-6:ymax+6          
                        if(R(ij)>230&&R(ij)-G(ij)>30&&R(ij)-B(ij)>30)      %  红色像素判断条件
                            count(k)=count(k)+1;                           
                        end
                    end
                end
            end
            range=(xmax-xmin+12)*(ymax-ymin+12);
            if count(k)/range>0.01                   %红色像素阈值
                % count(k)
                t=t+1;
                % 存储数据以便后续识别和跟踪
                v(t)=k;
                area(t)=length(m);                % 区域面积
                x(t)=fix(sum(m)/area(t));         % 区域质心横坐标
                y(t)=fix(sum(n)/area(t));         % 区域质心纵坐标
                % 区域边界坐标
                xa(t)=xmax;                       
                xi(t)=xmin;
                ya(

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件     2300758  2015-03-25 23:33  colordetect\car2.avi
     文件    27717632  2015-05-10 16:02  colordetect\car2detect.avi
     文件     2349834  2015-03-25 23:28  colordetect\one.avi
     文件       14529  2015-04-16 11:01  colordetect\tailestimate2.m
     目录           0  2015-07-23 10:11  colordetect\

评论

共有 条评论