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?
Best Answer