Can vision.For​egroundDet​ector work on GUI

Hi, Can I use GUI to display foreground from vision.ForegroundDetector? By using the same method I can extract the foreground. But in the GUI I can't display the foreground. Please help, thanks

3 件のコメント

Image Analyst
Image Analyst 2017 年 8 月 14 日
Why not? Did you call imshow()?
Leona Chan
Leona Chan 2017 年 8 月 14 日
Yes, I had. I can display the frame, but foreground cannot. These are some pieces of code
function playCallback(hObject,~,videoSrc,hAxes)
while strcmp(hObject.String, 'Pause') && ~isDone(videoSrc)
[frame,result] = getAndProcessFrame(videoSrc);
showFrameOnAxis(hAxes.axis1, frame);
showFrameOnAxis(hAxes.axis2, result);
end
function [frame,foreground] = getAndProcessFrame(videoSrc)
foregroundDetector = vision.ForegroundDetector('NumGaussians', 4, ... 'NumTrainingFrames', 60);
frame = step(videoSrc);
foreground = step(foregroundDetector, frame); end
Jiro Doke
Jiro Doke 2017 年 8 月 15 日
編集済み: Jiro Doke 2017 年 8 月 15 日
What do you mean by "you can't display the foreground"? Do you get an error? Does it show something but not what you expect? Is it possible that for the frame input, no foreground was detected? What exactly is the situation?

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

 採用された回答

Leona Chan
Leona Chan 2017 年 8 月 15 日

0 投票

As above code, showFrameOnAxis(hAxes.axis1, frame); showFrameOnAxis(hAxes.axis2, foreground); The frame can show in both axis1 or axis2, but put foreground either axis1 or axis2 also nothing to display.

6 件のコメント

Jiro Doke
Jiro Doke 2017 年 8 月 15 日
(If possible, please move this to the Comments section above, since this is the "Answers" section)
Please be a bit more clear. When you say "nothing to display", does it show all black? All white? Something else? Do you see error messages in the Command Window?
Leona Chan
Leona Chan 2017 年 8 月 15 日
All black and no message in the command window
Jiro Doke
Jiro Doke 2017 年 8 月 15 日
That probably means that the algorithm didn't detect any foreground. Detected foreground would show up in white (in the black&white image).
Leona Chan
Leona Chan 2017 年 8 月 15 日
But I can extract the foreground by the same method.
Jiro Doke
Jiro Doke 2017 年 8 月 15 日
"Same method" as in using foregroundDetector in a loop with video frames?
I can't say for certain, but you may need to take the vision.ForegroundDetector initialization outside of the "loop". If I remember correctly, the detector uses past frames to estimate the background. Currently, in your snippet of code, you are recreating the detector for each frame, thus clearing the past frames from its algorithm. Just using your code snippet, you may need to change to something like this.
function playCallback(hObject,~,videoSrc,hAxes)
foregroundDetector = vision.ForegroundDetector('NumGaussians', 4, ...
'NumTrainingFrames', 60);
while strcmp(hObject.String, 'Pause') && ~isDone(videoSrc)
[frame,result] = getAndProcessFrame(videoSrc,foregroundDetector);
showFrameOnAxis(hAxes.axis1, frame);
showFrameOnAxis(hAxes.axis2, result);
end
end
function [frame,foreground] = getAndProcessFrame(videoSrc,foregroundDetector)
frame = step(videoSrc);
foreground = step(foregroundDetector, frame);
end
Leona Chan
Leona Chan 2017 年 8 月 15 日
Yes, work now, thank you very much

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeImage Processing and Computer Vision についてさらに検索

質問済み:

2017 年 8 月 14 日

コメント済み:

2017 年 8 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by