frame_difference_test_harness.m

来自「This m-file implements the frame differe」· M 代码 · 共 47 行

M
47
字号
% This m-file implements the frame difference algorithm for background
% subtraction.  
clear all

% source = aviread('C:\Video\Source\traffic\san_fran_traffic_30sec_QVGA');
source = aviread('..\test_video\san_fran_traffic_30sec_QVGA_Cinepak');

thresh = 25;           

bg = source(1).cdata;           % read in 1st frame as background frame
bg_bw = rgb2gray(bg);     % convert background to greyscale


% ----------------------- set frame size variables -----------------------
fr_size = size(bg);             
width = fr_size(2);
height = fr_size(1);
fg = zeros(height, width);


% --------------------- process frames -----------------------------------

fxp_init('sw');                 % initialize Catalytic fixed-point libraries 

for i = 2:length(source)
    
    fr = source(i).cdata;       % read in frame
    

    fr_fxp_r = fxp(double(fr(:,:,1)),8,0,'u');
    fr_fxp_g = fxp(double(fr(:,:,2)),8,0,'u');
    fr_fxp_b = fxp(double(fr(:,:,3)),8,0,'u');
    bg_bw_fxp = fxp(double(bg_bw),8,0,'u');
    

    [fr_bw, fg, bg_bw ] = fr_diff_ct(bg_bw_fxp,fr_fxp_r,fr_fxp_g,fr_fxp_b,thresh,width,height);
   
    figure(1),subplot(3,1,1),imshow(fr)
    subplot(3,1,2),imshow(uint8(fr_bw))
    subplot(3,1,3),imshow(uint8(fg))
  
%     pause   
    
end

    
    

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?