% trafficObj1 = mmreader('traffic.avi');
trafficObj1 = VideoReader('traffic.avi');
mplay('traffic.avi');
darkCarValue=70;
darkCar=rgb2gray(read(trafficObj1,71));
%noDarkCar=imextendedmax(darkCar,darkCarValue);
%imshow(darkCar);
%figure,imshow(noDarkCar);
sedisk=strel('disk',2);
%noSmallStructures=imopen(noDarkCar,sedisk);
%imshow(noSmallStructures);
nframes=get(trafficObj1,'NumberOfFrames'); %帧数
I=read(trafficObj1,1); %读取第一帧
taggedCars=zeros([size(I,1) size(I,2) 3 nframes],class(I)); %定义一个4维数组存放每一帧
for k=1:nframes
singleFrame = read(trafficObj1,k); %读取第k帧
I=rgb2gray(singleFrame); %转换为灰度图像