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
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Tracking and Motion Estimation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!