Control System Lab Report
Control System Lab Report
COMMUNICATION ENGINEERING
Code :
roi = [100 80 360 240];
maxNumObj = 200;
alarmCount = 45;
maxConsequtiveMiss = 4;
areaChangeFraction = 13;
centroidChangeFraction = 18;
minPersistenceRatio = 0.7;
PtsOffset = int32(repmat([roi(1), roi(2), 0, 0],[maxNumObj 1]));
hVideoSrc = vision.VideoFileReader;
hVideoSrc.Filename = 'viptrain.avi';
hVideoSrc.VideoOutputDataType = 'single';
hAbandonedObjects = vision.VideoPlayer('Name','Detected
Object','Position',pos);
pos(1) = 46+roi(3);
hAllObjects = vision.VideoPlayer('Name','All Objects','Position',pos);
pos = [80+2*roi(3) 300 roi(3)-roi(1)+25 roi(4)-roi(2)+25];
hThresholdDisplay = vision.VideoPlayer('Name','Threshold','Position',pos);
firsttime = true;
while ~isDone(hVideoSrc)
Im = step(hVideoSrc);
OutIm = Im(roi(2):end, roi(1):end, :);
YCbCr = step(hColorConv, OutIm);
CbCr = complex(YCbCr(:,:,2), YCbCr(:,:,3));
if firsttime
firsttime = false;
BkgY = YCbCr(:,:,1);
BkgCbCr = CbCr;
end
SegY = step(hAutothreshold, abs(YCbCr(:,:,1)-BkgY));
SegCbCr = abs(CbCr-BkgCbCr) > 0.05;
Segmented = step(hClosing, SegY | SegCbCr);
[Area,Centroid,BBox] = step(hBlob,Segmented);
[OutCount,OutBBox] = videoobjtracker(Area,Centroid,BBox,maxNumObj,...
areaChangeFraction,centroidChangeFraction,maxConsequtiveMiss,....
minPersistenceRatio,alarmCount);
Imr =
insertShape(Im,'FilledRectangle',OutBBox+PtsOffset,'Color','red','Opacity',0.5);
Imr = insertText(Imr, [1,1], OutCount);
step(hAbandonedObjects, Imr);
BlobCount = size(BBox,1);
BBoxOffset = BBox + int32(repmat([roi(1) roi(2) 0 0],[BlobCount 1]));
Imr = insertShape(Im,'Rectangle',BBoxOffset,'Color','green');
Imr = insertText(Imr, [1,1],OutCount);
Imr = insertShape(Imr,'Rectangle',roi);
step(hAllObjects, Imr);
SegBBox = PtsOffset;
SegBBox(1:BlobCount,:) = BBox;
SegIm = insertShape(double(repmat(Segmented,[1 1
3])),'Rectangle',SegBBox,'Color','green');
step(hThresholdDisplay, SegIm);
end
release(hVideoSrc);
Output