How to play video after background subtraction with deployable video player?

2 次查看(过去 30 天)
This is my first time using MATLAB, I'm still adapting myself with the language.. What I want to ask is, if I just used this code from help document for gaussian mixture model background substraction:
videoSource = vision.VideoFileReader('3.avi','ImageColorSpace','Intensity','VideoOutputDataType','uint8');
detector = vision.ForegroundDetector(...
'NumTrainingFrames', 5, ... % 5 because of short video
'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();
while ~isDone(videoSource)
frame = step(videoSource);
fgMask = step(detector, frame);
bbox = step(blob, fgMask);
out = step(shapeInserter, frame, bbox); % draw bounding boxes around cars
step(videoPlayer, out); % view results in the video player
end
release(videoPlayer);
release(videoSource);
the video playing so fast.. And I found if I play video only without background substraction with deployable video player, it's play like in windows movie player.. My question is how I can play with deployable video player after using gaussian mixture model background substraction?

回答(1 个)

Dima Lisin
Dima Lisin 2015-1-15
Hi Shiloh,
the line
step(videoPlayer, out); % view results in the video player
tells the vision.VideoPlayer object to display image out, which is the original video frame with the bounding boxes. If you want to show the result of the background subtraction, you should replace out with fgMask.
If you wish to use vision.DeployableVideoPlayer, then you should simply replace
videoPlayer = vision.VideoPlayer();
with
videoPlayer = vision.DeployableVideoPlayer();
You can also play the video and the foreground mask side by side using two video players. See the Motion-Based Multiple Object Tracking example.
  2 个评论
Shiloh Pho
Shiloh Pho 2015-1-23
Hello, thank you for your help.. Can I ask again? Is there any command in matlab that can delay each frame?
Dima Lisin
Dima Lisin 2015-1-23
Hi Shiloh,
I am not quite sure what you mean by "delay"... Is your video playing too fast? You can use the pause function to cause matlab to wait for some amount of time.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by