资源简介

改进后三帧差法的多帧融合差分法,改变原有提取帧的方法

资源截图

代码片段和文件信息

clc;
clear all;

targetavi=‘走过1.avi‘;                             %%原始视频
resultavi=‘result1.avi‘;                                  %%检测结果视频

%%%%%%%%%%%%%%%%%%%%%%读取视频
mov=aviread(targetavi);
%mov=mmreader(targetavi);
fnum=size(mov2);

%%%%%%%%%%%%%%%%%%%%%%建立结果视频
aviobj = avifile(resultavi);
aviobj.Quality = 100;
aviobj.Fps = 25;
aviobj.compression=‘Indeo5‘;
%aviobj.compression=‘None‘;


%%%%%%%%%%%%%%%%%%%%%%帧间差分法
for i=4:fnum-3
    x1=mov(i-3).cdata(:::);
    x2=mov(i-2).cdata(:::);
    x3=mov(i-1).cdata(:::);
    y=mov(i).cdata(:::);
    z1=mov(i+1).cdata(:::);
    z2=mov(i+2).cdata(:::);
    z3=mov(i+3).cdata(:::);
    
        m1=rgb2gray(x1);
        m1=medfilt2(m1);%%
         m2=rgb2gray(x2);
        m2=medfilt2(m2);%%
         m3=rgb2gray(x3);
        m3=medfilt2(m3);%%

        n=rgb2gray(y);
        n=medfilt2(n);
        
       
         o1=rgb2gray(z1);
        o1=medfilt2(o1);
         o2=rgb2gray(z2);
        o2=medfilt2(o2);
       o3=rgb2gray(z3);
        o3=medfilt2(o3);

        q=im2double(n);
        w1=im2double(m1);
        w2=im2double(m2);
        w3=im2double(m3);
        p1=im2double(o1);
        p2=im2double(o2);
        p3=im2double(o3);
        
        c1=q-w1;%%前两帧差分
        c2=p3-q;
        g1=q-w2;
        g2=p2-q;
        h1=q-w3;
        h2=p1-q;
       
        t=40; %%阈值,此值可以调节
        t=t/256;%%转化为double型数据
        k1=find(abs(c1)>=t);%%find函数作用是找到图c中的值大于t的点坐标
        k2=find(abs(c2)>=t);
        k3=find(abs(g1)>=t);
        k4=find(abs(g2)>=t);
        k5=find(abs(h1)>=t);
        k6=find(abs(h2)>=t);
      
        c1(k1)=255;%%二值化的一
        c2(k2)=255;
        g1(k3)=255;
        g2(k4)=255;
        h1(k5)=255;
        h2(k6)=255;
        k1=find(abs(c1)        k2=find(abs(c2)        k3=find(abs(g1)        k4=find(abs(g2)        k5=find(abs(h1)        k6=find(abs(h2)        
        c1(k1)=0;
        c2(k2)=0;
       g1(k3)=0;
       g2(k4)=0;
      h1(k5)=0;
       h2(k6)=0;
        imshow(c1);
        imshow(c2);
        imshow(g1);
        imshow(g2);
        imshow(h1);
        imshow(h2);
       
        f1=c1&c2;
        f2=g1&g2;
        f3=h1&h2;
        %BW1 = im2bw(c t);%%二值化,t为阈值
        %BW2 = im2bw(b t);
        %f=c&b;%此时f已变为logical变量
        f=f1|f2|f3;
        x1=double(f);%将f转换为double变量
        
        imshow(x1);
        
        adata=cat(3x1x1x1);%%灰度图像生成视频必加此句
        %adata=cat(3bbb);
        %adata=cat(3ccc);
        aviobj = addframe(aviobjadata);%%生成视频,图片变为视频
        
        hold on;
    drawnow;
   hold off;
end
aviobj=close(aviobj);

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件        2835  2012-11-28 21:00  duozhen.m

评论

共有 条评论