Before the computer vision class, the teacher demonstrated a moving target detection program. Feel fun, go back and write a.
Moving target detection based on frame difference method + threshold (thresholds). The median filter was processed before the detection, and the threshold value was set manually. Effect of the general bar.
Clear all;
Close all;
CLC;
Mov=videoreader (' Classroom.avi ');
N=mov. Numberofframes;
For I=2:n
Frame=read (mov,i);
Pframe=read (mov,i-1);
If Ndims (frame) ==3
X=rgb2gray (frame);
else
X=frame;
End
If Ndims (pframe) ==3
Y=rgb2gray (pframe);
else
Y=pframe;
End
subplot (1,2,1);
Imshow (pframe,[]);
Title (sprintf ('%d frame ', i-1))
% difference Algorithm
x=medfilt2 (x);
Y=medfilt2 (y);
N=im2double (x);
P=im2double (y);
C=n-p;
C=MEDFILT2 (c);
t=10/256;
C (ABS (c) >=t) =255;
C (ABS (c) <t) =0;
C=logical (c);
X1=pframe (:,:, 1);
X1 (c) =0;
X2=pframe (:,:, 2);
X2 (c) =255;
X3=pframe (:,:, 3);
X3 (c) =0;
Xc=cat (3,x1,x2,x3);
Subplot (1,2,2);
Imshow (xc,[]);
Title (sprintf ('%d frame ', i-1)) End
Code and test data downloads