Crop video using ForegroundDetector?

조회 수: 4 (최근 30일)
Lydia
Lydia 2015년 2월 26일
답변: Dima Lisin 2015년 3월 1일
Hello,
I'm using ForegroundDetector to detect a moving object from a fixed camera video. I wondered if there is any way to use this to make a new video with everything but the object removed? I'm using this code from here and it can find the object perfectly, but I would like to produce a new video with everything outside the bounding box made black. Anyone have any ideas?
Thank you :)
videoSource = vision.VideoFileReader('moving.avi','ImageColorSpace','Intensity','VideoOutputDataType','uint8');
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();
while ~isDone(videoSource)
frame = step(videoSource);
fgMask = step(detector, frame);
bbox = step(blob, fgMask);
out = step(shapeInserter, frame, bbox); % draw bounding boxes around object
step(videoPlayer, out); % view results in the video player
end
release(videoPlayer);
release(videoSource);

답변 (1개)

Dima Lisin
Dima Lisin 2015년 3월 1일
You can do that using the foreground mask:
frameWithNoBackground = frame .* fgMask;

카테고리

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