Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
vision.ForegroundDetector on Images

Subject: vision.ForegroundDetector on Images

From: Gordon

Date: 28 Mar, 2012 08:52:11

Message: 1 of 13

Hi,

I would like to know if I can use the vision.ForegroundDetector on images instead of on a video sequence. I am currently using Matlab 2011a.

Thanks a lot for your time and help.

Subject: vision.ForegroundDetector on Images

From: witek@mathworks.com

Date: 28 Mar, 2012 13:59:07

Message: 2 of 13

Hi Gordon,

vision.ForegroundDetector analyzes data over time. It ultimately relies on detecting changes in a sequence.
You can feed it video or a series of images but the images must represent a sequence in time.

Witek


Gordon <gordon.aguis91@gmail.com> wrote:
> Hi,
>
> I would like to know if I can use the vision.ForegroundDetector on images instead of on a video sequence. I am currently using Matlab 2011a.
>
> Thanks a lot for your time and help.

Subject: vision.ForegroundDetector on Images

From: Gordon

Date: 28 Mar, 2012 14:08:25

Message: 3 of 13

Thanks a lot! Yes, my data changes with time, it is like a video sequence but it is made up of images.
I was wondering whether there exists something like vision.VideoFileReader() but for images instead.

Thanks.

Subject: vision.ForegroundDetector on Images

From: witek@mathworks.com

Date: 28 Mar, 2012 15:33:10

Message: 4 of 13

Hi Gordon,

We'll consider adding an object like this in the future.
In the meantime, you can use the following strategy:

imageNames = dir(fullfile(<your directory>,'*.jpg'));
imageNames = {imageNames.name}';

% you may need to sort the file names at this point in time, see
% http://www.mathworks.com/products/matlab/demos.html?file=/products/demos/shipping/matlab/imagesAndVideo.html#16
% for details

foregroundEst = vision.ForegroundEstimator;

for ii = 1:length(imageNames)
  img = imread(fullfile(workingDir,'images',imageNames{ii}));

  fg = foregroundEst.step(img);

  <do whatever else needs to be done>

end

HTH,

Witek


Gordon <gordon.aguis91@gmail.com> wrote:
> Thanks a lot! Yes, my data changes with time, it is like a video sequence but it is made up of images.
> I was wondering whether there exists something like vision.VideoFileReader() but for images instead.
>
> Thanks.

Subject: vision.ForegroundDetector on Images

From: Gordon

Date: 28 Mar, 2012 16:04:19

Message: 5 of 13

Thanks a lot once again! Your help is greatly appreciated.

Subject: vision.ForegroundDetector on Images

From: Gordon

Date: 28 Mar, 2012 16:07:24

Message: 6 of 13

Thanks a lot! Your help is greatly appreciated.

witek@mathworks.com wrote in message <jkvavm$j01$1@newscl01ah.mathworks.com>...
> Hi Gordon,
>
> We'll consider adding an object like this in the future.
> In the meantime, you can use the following strategy:
>
> imageNames = dir(fullfile(<your directory>,'*.jpg'));
> imageNames = {imageNames.name}';
>
> % you may need to sort the file names at this point in time, see
> % http://www.mathworks.com/products/matlab/demos.html?file=/products/demos/shipping/matlab/imagesAndVideo.html#16
> % for details
>
> foregroundEst = vision.ForegroundEstimator;
>
> for ii = 1:length(imageNames)
> img = imread(fullfile(workingDir,'images',imageNames{ii}));
>
> fg = foregroundEst.step(img);
>
> <do whatever else needs to be done>
>
> end
>
> HTH,
>
> Witek
>
>
> Gordon <gordon.aguis91@gmail.com> wrote:
> > Thanks a lot! Yes, my data changes with time, it is like a video sequence but it is made up of images.
> > I was wondering whether there exists something like vision.VideoFileReader() but for images instead.
> >
> > Thanks.

Subject: vision.ForegroundDetector on Images

From: Gordon

Date: 29 Mar, 2012 10:56:19

Message: 7 of 13

Hi,

Sorry to bother again. Can you please show me how I can modify this code to draw boxes around the detected objects in the images please?

Thanks so much for your time!

"Gordon" wrote in message <jkvcvs$t4k$1@newscl01ah.mathworks.com>...
> Thanks a lot! Your help is greatly appreciated.
>
> witek@mathworks.com wrote in message <jkvavm$j01$1@newscl01ah.mathworks.com>...
> > Hi Gordon,
> >
> > We'll consider adding an object like this in the future.
> > In the meantime, you can use the following strategy:
> >
> > imageNames = dir(fullfile(<your directory>,'*.jpg'));
> > imageNames = {imageNames.name}';
> >
> > % you may need to sort the file names at this point in time, see
> > % http://www.mathworks.com/products/matlab/demos.html?file=/products/demos/shipping/matlab/imagesAndVideo.html#16
> > % for details
> >
> > foregroundEst = vision.ForegroundEstimator;
> >
> > for ii = 1:length(imageNames)
> > img = imread(fullfile(workingDir,'images',imageNames{ii}));
> >
> > fg = foregroundEst.step(img);
> >
> > <do whatever else needs to be done>
> >
> > end
> >
> > HTH,
> >
> > Witek
> >
> >
> > Gordon <gordon.aguis91@gmail.com> wrote:
> > > Thanks a lot! Yes, my data changes with time, it is like a video sequence but it is made up of images.
> > > I was wondering whether there exists something like vision.VideoFileReader() but for images instead.
> > >
> > > Thanks.

Subject: vision.ForegroundDetector on Images

From: witek@mathworks.com

Date: 29 Mar, 2012 16:31:08

Message: 8 of 13

Hi,

If you'd like to look at a single image a function such as RECTANGLE or ANNOTATION will work well.
If you'd like to do it in a loop and then use a video viewer, your best bet is to use vision.ShapeInserter object:

hshapeins = vision.ShapeInserter;

In a loop you'd do something like this:

x = 25; y = 15; width = 40; height = 40; % you'd replace this line with object detection routine which produces
                                         % a bounding box in a form [x y width height]
rectangle = [x y width height];

J = step(hshapeins, I, pts);

% then display J using vision.VideoViewer

Witek


Gordon <gordon.aguis91@gmail.com> wrote:
> Hi,
>
> Sorry to bother again. Can you please show me how I can modify this code to draw boxes around the detected objects in the images please?
>
> Thanks so much for your time!
>
> "Gordon" wrote in message <jkvcvs$t4k$1@newscl01ah.mathworks.com>...
> > Thanks a lot! Your help is greatly appreciated.
> >
> > witek@mathworks.com wrote in message <jkvavm$j01$1@newscl01ah.mathworks.com>...
> > > Hi Gordon,
> > >
> > > We'll consider adding an object like this in the future.
> > > In the meantime, you can use the following strategy:
> > >
> > > imageNames = dir(fullfile(<your directory>,'*.jpg'));
> > > imageNames = {imageNames.name}';
> > >
> > > % you may need to sort the file names at this point in time, see
> > > % http://www.mathworks.com/products/matlab/demos.html?file=/products/demos/shipping/matlab/imagesAndVideo.html#16
> > > % for details
> > >
> > > foregroundEst = vision.ForegroundEstimator;
> > >
> > > for ii = 1:length(imageNames)
> > > img = imread(fullfile(workingDir,'images',imageNames{ii}));
> > >
> > > fg = foregroundEst.step(img);
> > >
> > > <do whatever else needs to be done>
> > >
> > > end
> > >
> > > HTH,
> > >
> > > Witek
> > >
> > >
> > > Gordon <gordon.aguis91@gmail.com> wrote:
> > > > Thanks a lot! Yes, my data changes with time, it is like a video sequence but it is made up of images.
> > > > I was wondering whether there exists something like vision.VideoFileReader() but for images instead.
> > > >
> > > > Thanks.

Subject: vision.ForegroundDetector on Images

From: Lo

Date: 18 Oct, 2012 13:29:09

Message: 9 of 13

"Gordon" wrote in message <jkujfr$30c$1@newscl01ah.mathworks.com>...
> Hi,
>
> I would like to know if I can use the vision.ForegroundDetector on images instead of on a video sequence. I am currently using Matlab 2011a.
>
> Thanks a lot for your time and help.

Sorry,May I ask how to use this function on RGB avi video?

Subject: vision.ForegroundDetector on Images

From: witek@mathworks.com

Date: 18 Oct, 2012 14:28:42

Message: 10 of 13

Lo <roger572.ee96@g2.nctu.edu.tw> wrote:
> "Gordon" wrote in message <jkujfr$30c$1@newscl01ah.mathworks.com>...
> > Hi,
> >
> > I would like to know if I can use the vision.ForegroundDetector on images instead of on a video sequence. I am currently using Matlab 2011a.
> >
> > Thanks a lot for your time and help.
>
> Sorry,May I ask how to use this function on RGB avi video?

To use it with RGB, you simply feed it RGB video frames. You start by setting up your video reader such that
it returns color frames, and then you pass them as inputs to the step() method of the vision.ForegroundDetector.

Witek

Subject: vision.ForegroundDetector on Images

From: John

Date: 26 Nov, 2012 13:45:12

Message: 11 of 13

Hi all,

I just wonder what kind of image feature that ForegroundDetector cuntion uses to classified between background and foreground. If there is any simple tutorial about this, please let me know the link.

Thank you very much.

witek@mathworks.com wrote in message <jkv5fb$sil$1@newscl01ah.mathworks.com>...
> Hi Gordon,
>
> vision.ForegroundDetector analyzes data over time. It ultimately relies on detecting changes in a sequence.
> You can feed it video or a series of images but the images must represent a sequence in time.
>
> Witek
>
>
> Gordon <gordon.aguis91@gmail.com> wrote:
> > Hi,
> >
> > I would like to know if I can use the vision.ForegroundDetector on images instead of on a video sequence. I am currently using Matlab 2011a.
> >
> > Thanks a lot for your time and help.

Subject: vision.ForegroundDetector on Images

From: witek@mathworks.com

Date: 26 Nov, 2012 14:04:39

Message: 12 of 13


This is the paper that you should read:

http://www.google.com/url?sa=t&rct=j&q=stoufer%20and%20grimson&source=web&cd=1&cad=rja&ved=0CDEQFjAA&url=http%3A%2F%2Fwww.ai.mit.edu%2Fprojects%2Fvsam%2FPublications%2Fstauffer_cvpr98_track.pdf&ei=zHazUMCcLaSt0AHQtIC4BA&usg=AFQjCNERJxusL_4C7-VyJmHKPWgOWl9_zw

Witek

John <on.virtual.life@gmail.com> wrote:
> Hi all,
>
> I just wonder what kind of image feature that ForegroundDetector cuntion uses to classified between background and foreground. If there is any simple tutorial about this, please let me know the link.
>
> Thank you very much.
>
> witek@mathworks.com wrote in message <jkv5fb$sil$1@newscl01ah.mathworks.com>...
> > Hi Gordon,
> >
> > vision.ForegroundDetector analyzes data over time. It ultimately relies on detecting changes in a sequence.
> > You can feed it video or a series of images but the images must represent a sequence in time.
> >
> > Witek
> >
> >
> > Gordon <gordon.aguis91@gmail.com> wrote:
> > > Hi,
> > >
> > > I would like to know if I can use the vision.ForegroundDetector on images instead of on a video sequence. I am currently using Matlab 2011a.
> > >
> > > Thanks a lot for your time and help.

Subject: vision.ForegroundDetector on Images

From: varma.pratik89@gmail.com

Date: 28 Feb, 2014 10:41:52

Message: 13 of 13


i have to use live video from webcam with foregrounddetector can u help plz,it tracks whole area instead of it should track only moving object. my code is like this,
vision.ForegroundDetector
clc;
close all;
imtool close all;
clear;
workspace;
fontSize = 8;

foregroundDetector = vision.ForegroundDetector('NumGaussians', 3,'MinimumBackgroundRatio',0.9, ...
    'NumTrainingFrames', 700);
blobAnalysis = vision.BlobAnalysis('BoundingBoxOutputPort', true, ...
    'AreaOutputPort', false, 'CentroidOutputPort', false, ...
    'MinimumBlobArea', 250);

vid = videoinput('winvideo', 1, 'YUY2_320x240'); %select input device
hvpc = vision.VideoPlayer; %create video player object
src = getselectedsource(vid);
vid.FramesPerTrigger =1;
vid.TriggerRepeat = Inf;
vid.ReturnedColorspace = 'rgb';
src.FrameRate = '30';
start(vid)

        i=0;
        while (i<=20)

data = getsnapshot(vid);
subplot(2,2,1);
imshow(data);
foreground = step(foregroundDetector, data);
subplot(2,2,2);
imshow(foreground);
se = strel('square', 3);
filteredForeground = imopen(foreground, se);

% u = 0.9;
% if i == 0
% bg = zeros(size(data));
% else
% bg = (1-u)*double(data) + u*bg;
% end
% dif = abs(data-uint8(bg) );
%
% grayImage = rgb2gray(dif);% Convert to gray level
% level = 0.1;
% bw = im2bw( dif, level);
% BW5 = imfill(bw,'holes');
% bw6 = bwlabel(BW5, 8);

bbox = step(blobAnalysis,filteredForeground);
result = insertShape(data, 'Rectangle', bbox, 'Color', 'green');
% subplot(1,1,1);
% imshow(result);
step(hvpc, result);
stop(vid)
flushdata(vid);
i=i+1;
        end
      
        

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us