Error while using foreground detection in matlab with webcam video?

3 ビュー (過去 30 日間)
Aravind
Aravind 2014 年 9 月 17 日
コメント済み: Aravind 2014 年 9 月 18 日
clear all
% video object to grab frame from live video
vidobj = imaq.VideoDevice('winvideo', 1);
detector = vision.ForegroundDetector(...
'NumTrainingFrames', 50, ... %
'InitialVariance', 30*30); % initial standard deviation of 30
blob = vision.BlobAnalysis(...
'CentroidOutputPort', false, 'AreaOutputPort', false, ...
'BoundingBoxOutputPort', true, ...
'MinimumBlobAreaSource', 'Property', 'MinimumBlobArea', 250);
shapeInserter = vision.ShapeInserter('BorderColor','White');
videoPlayer = vision.VideoPlayer();
for n=1:500
f = step(vidobj);
frame = rgb2gray(f);
fgMask = step(detector, frame);
bbox = step(blob, fgMask);
%out = step(shapeInserter, frame, fgMask); % draw bounding boxes
step(videoPlayer, fgMask); % view results in the video player
end
release(vidobj);
release(videoPlayer);
This is the initial code I've written, I'm trying to display the masked frame, so it should come in black and white where the white ones are the foreground object. But all I get is a completely black output stream. Where have I gone wrong?

採用された回答

Dima Lisin
Dima Lisin 2014 年 9 月 17 日
編集済み: Dima Lisin 2014 年 9 月 17 日
Hi Aravind,
This is probably because the 'InitialVariance' of the foreground detector is not appropriate for the frame datatype. The value of 30^2 works for 'uint8'. However, the default data type of the frame returned by the step() method of imaq.VideoDevice is 'single'. So you should either do
vidobj = imaq.VideoDevice('winvideo', 1, 'ReturnedDataType', 'uint8');
or set 'InitialVariance' to (30 / 255)^2.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeComputer Vision Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by