Hi, how to accumulate total number of cars detection and reset to zero at specified time period in "Detecting Cars Using Gaussian Mixture Models"?

1 回表示 (過去 30 日間)
clear
foregroundDetector = vision.ForegroundDetector('NumGaussians', 3, ... 'NumTrainingFrames', 50);
videoReader = vision.VideoFileReader('visiontraffic.avi'); for i = 1:150 frame = step(videoReader); foreground = step(foregroundDetector, frame); end
total=0; figure; imshow(frame); title('Video Frame');
figure; imshow(foreground); title('Foreground');
se = strel('square', 3); filteredForeground = imopen(foreground, se); figure; imshow(filteredForeground); title('Clean Foreground');
blobAnalysis = vision.BlobAnalysis('BoundingBoxOutputPort', true, ... 'AreaOutputPort', false, 'CentroidOutputPort', false, ... 'MinimumBlobArea', 150); bbox = step(blobAnalysis, filteredForeground);
result = insertShape(frame, 'Rectangle', bbox, 'Color', 'green');
numCars= size(bbox, 1);
result = insertText(result, [100 100], total, 'BoxOpacity', 1, ...
'FontSize', 14);
figure; imshow(result); title('Detected Cars');
videoPlayer = vision.VideoPlayer('Name', 'Detected Cars'); videoPlayer.Position(3:4) = [650,400]; % window size: [width, height] se = strel('square', 3);
while ~isDone(videoReader)
frame = step(videoReader); % read the next video frame
foreground = step(foregroundDetector, frame);
filteredForeground = imopen(foreground, se);
bbox = step(blobAnalysis, filteredForeground);
result = insertShape(frame, 'Rectangle', bbox, 'Color', 'green');
numCars = size(bbox, 1);
for i=1:1:numCars
total=total+bbox(i);
end
result = insertText(result, [10 10], total, 'BoxOpacity', 1, ...
'FontSize', 14);
step(videoPlayer, result);
end

回答 (0 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by