error using blobAnalysis/step

1 次查看(过去 30 天)
izza aditya
izza aditya 2019-8-27
filename = '../dataset/video.avi';
hsrc = vision.VideoFileReader(filename,'ImageColorSpace','RGB','VideoOutputDataType','uint8');
% ------------------------------------------------------------------------------------------
blobAnalysis = vision.BlobAnalysis('BoundingBoxOutputPort', true, ...
'AreaOutputPort', true, 'CentroidOutputPort', true, ...
'MinimumBlobArea', 50);
se = strel('square',3);
% -------------------------------------------------------------------------------------------
% Create background/foreground segmentation object
hfg = backgroundSubtractor(algorithm);
disp('Starting...');
frameCnt = 1;
while ~isDone(hsrc), %disp(frameCnt)
% Read frame
frame = step(hsrc);
% Compute foreground mask and background model
[fgMask, bgModel] = getForegroundMask(hfg, frame);
%--------------------------------------------------------------------------
filteredForeground = imopen(fgMask, se);
bbox = step(blobAnalysis, filteredForeground);
result = insertShape(hsrc, 'Rectangle', bbox, 'Color', 'green');
numCars = size(bbox, 1);
result = insertText(result, [10 10], numCars, 'BoxOpacity', 1, ...
% 'FontSize', 14);
%--------------------------------------------------------------------------
% View results
subplot(2,3,1), imshow(frame,'InitialMagnification','fit');
subplot(2,3,2), imshow(filteredForeground,'InitialMagnification','fit');
subplot(2,3,3), imshow(bgModel,'InitialMagnification','fit');
subplot(2,3,4), imshow(fgMask,'InitialMagnification','fit');
pause(0.01);
% Reset background model
% This step just demonstrates how to use reset method
if (frameCnt==5)
%reset(hfg);
%break;
end
frameCnt = frameCnt + 1;
end
disp('Finished!');
release(hfg);
release(hsrc);

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Tracking and Motion Estimation 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by