How to crop images and save it to matrix after vision.For​egroundDet​ector

1 回表示 (過去 30 日間)
Kong
Kong 2020 年 3 月 19 日
コメント済み: Image Analyst 2020 年 3 月 22 日
Hello. Vision.ForegroundDetector is so amazing!
Could you let me know how to get several images inbox as a matrix?
I want to save these images as matrix.
I want to use several images like this. How can I crop this like image?
I am using this code.
videoSource = VideoReader('shahar_run.avi');
detector = vision.ForegroundDetector(...
'NumTrainingFrames', 5, ...
'InitialVariance', 30*30);
blob = vision.BlobAnalysis(...
'CentroidOutputPort', false, 'AreaOutputPort', false, ...
'BoundingBoxOutputPort', true, ...
'MinimumBlobAreaSource', 'Property', 'MinimumBlobArea', 250);
shapeInserter = vision.ShapeInserter('BorderColor','White');
videoPlayer = vision.VideoPlayer();
while hasFrame(videoSource)
frame = readFrame(videoSource);
fgMask = detector(frame);
bbox = blob(fgMask);
out = shapeInserter(fgMask,bbox);
videoPlayer(out);
pause(0.1);
end
  2 件のコメント
Ameer Hamza
Ameer Hamza 2020 年 3 月 22 日
Can you attach the actual image or the video file?
Kong
Kong 2020 年 3 月 22 日
I attached the video. Thank you so much.

サインインしてコメントする。

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 3 月 22 日
Check the following code
videoSource = VideoReader('denis_wave2.avi');
detector = vision.ForegroundDetector(...
'NumTrainingFrames', 5, ...
'InitialVariance', 30*30);
blob = vision.BlobAnalysis(...
'CentroidOutputPort', false, 'AreaOutputPort', false, ...
'BoundingBoxOutputPort', true, ...
'MinimumBlobAreaSource', 'Property', 'MinimumBlobArea', 50);
shapeInserter = vision.ShapeInserter('BorderColor','White');
videoPlayer = vision.VideoPlayer();
bounding_boxes = {};
while hasFrame(videoSource)
frame = readFrame(videoSource);
fgMask = detector(frame);
bbox = blob(fgMask);
for i=1:size(bbox, 1)
x = bbox(i, :);
bounding_boxes{end+1} = fgMask(x(2):sum(x([2 4])), x(1):sum(x([1 3])));
end
out = shapeInserter(fgMask,bbox);
videoPlayer(out);
pause(0.1);
end
The bounding_boxes is a cell array and its each element is a cropped image. You can check the output as
imshow(bounding_boxes{1})
imshow(bounding_boxes{2})
  6 件のコメント
Kong
Kong 2020 年 3 月 22 日
Thank you so much. I will.
Image Analyst
Image Analyst 2020 年 3 月 22 日
Get state of the art algorithms in gesture recognition here in Vision Bibliography

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by