hbfr = vision.BinaryFileReader( ...
'Filename', 'viptraffic.bin');
hcr = vision.ChromaResampler(...
'Resampling', '4:2:0 (MPEG1) to 4:4:4', ...
'InterpolationFilter', 'Pixel replication');
hcsc1 = vision.ColorSpaceConverter('Conversion', 'YCbCr to RGB');
hcsc2 = vision.ColorSpaceConverter('Conversion', 'RGB to intensity');
idtc = vision.ImageDataTypeConverter('OutputDataType', 'single');
hof = vision.OpticalFlow( ...
'OutputValue', 'Horizontal and vertical components in complex form', ...
'ReferenceFrameDelay', 3);
hmean1 = vision.Mean;
hmean2 = vision.Mean('RunningMean', true);
hmedianfilt = vision.MedianFilter;
hclose = vision.MorphologicalClose('Neighborhood', strel('line',5,45));
hblob = vision.BlobAnalysis( ...
'CentroidOutputPort', false, ...
'AreaOutputPort', true, ...
'BoundingBoxOutputPort', true, ...
'OutputDataType', 'double', ...
'NumBlobsOutputPort', false, ...
'MinimumBlobAreaSource', 'Property', ...
'MinimumBlobArea', 250, ...
'MaximumBlobAreaSource', 'Property', ...
'MaximumBlobArea', 3600, ...
'FillValues', -1, ...
'MaximumCount', 80);
herode = vision.MorphologicalErode('Neighborhood', strel('square',2));
hshapeins1 = vision.ShapeInserter( ...
'BorderColor', 'Custom', ...
'CustomBorderColor', [0 1 0]);
hshapeins2 = vision.ShapeInserter( ...
'Shape','Lines', ...
'BorderColor', 'Custom', ...
'CustomBorderColor', [255 255 0]);
htextins = vision.TextInserter( ...
'Text', '%4d', ...
'Location', [0 0], ...
'Color', [1 1 1], ...
'FontSize', 12);
sz = get(0,'ScreenSize');
pos = [20 sz(4)-300 200 200];
hVideo1 = vision.VideoPlayer('Name','Original Video','Position',pos);
pos(1) = pos(1)+220; % move the next viewer to the right
hVideo2 = vision.VideoPlayer('Name','Motion Vector','Position',pos);
pos(1) = pos(1)+220;
hVideo3 = vision.VideoPlayer('Name','Thresholded Video','Position',pos);
pos(1) = pos(1)+220;
hVideo4 = vision.VideoPlayer('Name','Results','Position',pos);
% Initialize some variables used in plotting motion vectors.
MotionVecGain = 20;
line_row = 22;
borderOffset = 5;
decimFactorRow = 5;
decimFactorCol = 5;
firstTime = true;